Class: BMC::MiniModelSerializer::Serialize
- Inherits:
-
Object
- Object
- BMC::MiniModelSerializer::Serialize
- Defined in:
- app/libs/bmc/mini_model_serializer/serialize.rb
Direct Known Subclasses
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
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(object, options = {}) ⇒ Serialize
constructor
A new instance of Serialize.
Constructor Details
#initialize(object, options = {}) ⇒ Serialize
Returns a new instance of Serialize.
8 9 10 11 |
# File 'app/libs/bmc/mini_model_serializer/serialize.rb', line 8 def initialize(object, = {}) @object = object @options = end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
2 3 4 |
# File 'app/libs/bmc/mini_model_serializer/serialize.rb', line 2 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'app/libs/bmc/mini_model_serializer/serialize.rb', line 2 def @options end |
Class Method Details
.call ⇒ Object
4 5 6 |
# File 'app/libs/bmc/mini_model_serializer/serialize.rb', line 4 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/libs/bmc/mini_model_serializer/serialize.rb', line 13 def call if object.is_a?(Hash) object.to_h { |k, v| [k.to_s, serialize(v)] } elsif object.is_a?(Enumerable) object.map { |e| serialize(e) } elsif (serializer = "#{object.class}Serializer".safe_constantize) serializer.call(object, ) else object.as_json end end |