Module: Ruact::Serializable::ClassMethods

Defined in:
lib/ruact/serializable.rb

Instance Method Summary collapse

Instance Method Details

#rsc_props(*attrs) ⇒ Object

Declare which instance methods should be included in the serialized payload. Raises ArgumentError at class-load time if any name has no corresponding method defined on the class.

Parameters:

  • attrs (Array<Symbol>)


26
27
28
29
30
31
32
33
34
# File 'lib/ruact/serializable.rb', line 26

def rsc_props(*attrs)
  attrs.each do |attr|
    unless method_defined?(attr)
      raise ArgumentError,
            "rsc_props: method `#{attr}` is not defined on #{self}"
    end
  end
  @rsc_props = attrs
end

#rsc_props_listArray<Symbol>

Returns the list of declared prop names as symbols. Walks the ancestor chain so subclasses inherit parent declarations.

Returns:

  • (Array<Symbol>)


40
41
42
43
44
45
46
47
48
# File 'lib/ruact/serializable.rb', line 40

def rsc_props_list
  klass = self
  while klass
    return klass.instance_variable_get(:@rsc_props) if klass.instance_variable_defined?(:@rsc_props)

    klass = klass.superclass
  end
  []
end