Class: SimpleObjectSerialization::Entity
- Inherits:
-
Object
- Object
- SimpleObjectSerialization::Entity
- Defined in:
- lib/simple_object_serialization/entity.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .attributes ⇒ Object
- .call(*params, **options, &block) ⇒ Object
- .define_attribute(name, options = {}, &block) ⇒ Object
- .object_alias(name) ⇒ Object
- .serialize(object, options = {}) ⇒ Object
- .serialize_collection(collection, options = {}) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(object, options = {}) ⇒ Entity
constructor
A new instance of Entity.
Constructor Details
#initialize(object, options = {}) ⇒ Entity
Returns a new instance of Entity.
7 8 9 10 |
# File 'lib/simple_object_serialization/entity.rb', line 7 def initialize(object, = {}) @object = object = end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/simple_object_serialization/entity.rb', line 5 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_object_serialization/entity.rb', line 5 def end |
Class Method Details
.attributes ⇒ Object
28 29 30 |
# File 'lib/simple_object_serialization/entity.rb', line 28 def self.attributes @attributes ||= Attributes.new end |
.call(*params, **options, &block) ⇒ Object
12 13 14 |
# File 'lib/simple_object_serialization/entity.rb', line 12 def self.call(*params, **, &block) new(*params, **).call(&block) end |
.define_attribute(name, options = {}, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/simple_object_serialization/entity.rb', line 22 def self.define_attribute(name, = {}, &block) attribute = Attribute.new(name, , block) attributes.push(attribute) end |
.object_alias(name) ⇒ Object
16 17 18 19 20 |
# File 'lib/simple_object_serialization/entity.rb', line 16 def self.object_alias(name) define_method(name) do object end end |
.serialize(object, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/simple_object_serialization/entity.rb', line 38 def self.serialize(object, = {}) hash = ObjectSerializer.call(self, object, ) JSON.generate(hash) end |
.serialize_collection(collection, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/simple_object_serialization/entity.rb', line 32 def self.serialize_collection(collection, = {}) hash = CollectionSerializer.call(self, collection, ) JSON.generate(hash) end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'lib/simple_object_serialization/entity.rb', line 44 def call self.class.attributes.hash_for(self) end |