Class: Mutils::Serialization::BaseSerializer
- Inherits:
-
Object
- Object
- Mutils::Serialization::BaseSerializer
- Defined in:
- lib/mutils/serialization/base_serializer.rb
Overview
BaseSerializer: inherit this class to get Serializer functionality
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(object, options = {}) ⇒ BaseSerializer
constructor
A new instance of BaseSerializer.
- #to_h ⇒ Object
- #to_json(_options = {}) ⇒ Object
Methods included from Results::Relations
Methods included from Results::Attributes
#fetch_attributes, #fetch_block_attributes
Methods included from Results::Main
#check_if_included, #class_name, #format_class_name, #generate_hash, #hashed_result, #scope_is_collection?
Methods included from SerializationMethods
Methods included from SerializationIncludes
Constructor Details
#initialize(object, options = {}) ⇒ BaseSerializer
Returns a new instance of BaseSerializer.
15 16 17 18 19 |
# File 'lib/mutils/serialization/base_serializer.rb', line 15 def initialize(object, = {}) [:child] = false unless [:child] self.scope = object self. = end |
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
9 10 11 |
# File 'lib/mutils/serialization/base_serializer.rb', line 9 def scope @scope end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mutils/serialization/base_serializer.rb', line 21 def as_json( = {}) if [:child] || !self.class.include_root to_h else { class_name => to_h } end end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/mutils/serialization/base_serializer.rb', line 29 def to_h generate_hash end |
#to_json(_options = {}) ⇒ Object
33 34 35 |
# File 'lib/mutils/serialization/base_serializer.rb', line 33 def to_json( = {}) JSON.generate(as_json, ) end |