module AnyCable::Rails::ChannelState::ClassMethods
def channel_state_attributes
def channel_state_attributes return @channel_state_attributes if instance_variable_defined?(:@channel_state_attributes) @channel_state_attributes = if superclass.respond_to?(:channel_state_attributes) superclass.channel_state_attributes.dup else [] end end
def state_attr_accessor(*names)
def state_attr_accessor(*names) names.each do |name| channel_state_attributes << name class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{name} return @#{name} if instance_variable_defined?(:@#{name}) @#{name} = AnyCable::Rails.deserialize(__istate__["#{name}"], json: true) if anycabled? end def #{name}=(val) __istate__["#{name}"] = AnyCable::Rails.serialize(val, json: true) if anycabled? instance_variable_set(:@#{name}, val) end RUBY end end