Module: Ruact::Serializable
- Defined in:
- lib/ruact/serializable.rb
Overview
Include this module in any Ruby object you want to pass as a prop to a client component. Declare which attributes are safe to serialize with rsc_props; only those attributes will be included in the wire payload.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#rsc_serialize ⇒ Hash{String => Object}
Serialize only the attributes declared with
rsc_props.
Class Method Details
.included(base) ⇒ Object
15 16 17 18 |
# File 'lib/ruact/serializable.rb', line 15 def self.included(base) base.extend(ClassMethods) base.instance_variable_set(:@rsc_props, []) end |
Instance Method Details
#rsc_serialize ⇒ Hash{String => Object}
Serialize only the attributes declared with rsc_props.
54 55 56 |
# File 'lib/ruact/serializable.rb', line 54 def rsc_serialize self.class.rsc_props_list.to_h { |attr| [attr.to_s, public_send(attr)] } end |