Class: Flexserializer::Base
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Flexserializer::Base
- Defined in:
- lib/flexserializer/base.rb
Class Attribute Summary collapse
-
.data_default_attributes ⇒ Object
Returns the value of attribute data_default_attributes.
-
.groups ⇒ Object
Returns the value of attribute groups.
Instance Attribute Summary collapse
-
#group_name ⇒ Object
readonly
Returns the value of attribute group_name.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_data ⇒ Object
- #define_attributes ⇒ Object
- #define_default_attrs ⇒ Object
- #define_group_attrs ⇒ Object
-
#initialize(object, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(object, options = {}) ⇒ Base
Returns a new instance of Base.
21 22 23 24 25 |
# File 'lib/flexserializer/base.rb', line 21 def initialize(object, = {}) @group_name = [:group] define_attributes super(object, ) end |
Class Attribute Details
.data_default_attributes ⇒ Object
Returns the value of attribute data_default_attributes.
4 5 6 |
# File 'lib/flexserializer/base.rb', line 4 def data_default_attributes @data_default_attributes end |
.groups ⇒ Object
Returns the value of attribute groups.
4 5 6 |
# File 'lib/flexserializer/base.rb', line 4 def groups @groups end |
Instance Attribute Details
#group_name ⇒ Object (readonly)
Returns the value of attribute group_name.
19 20 21 |
# File 'lib/flexserializer/base.rb', line 19 def group_name @group_name end |
Class Method Details
.default_attributes(&block) ⇒ Object
6 7 8 |
# File 'lib/flexserializer/base.rb', line 6 def default_attributes(&block) self.data_default_attributes = block end |
.group(*group_names, &block) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/flexserializer/base.rb', line 10 def group(*group_names, &block) self.groups ||= {} group_names.each do |name_group| self.groups[name_group] ||= [] self.groups[name_group] << block end end |
Instance Method Details
#clear_data ⇒ Object
33 34 35 |
# File 'lib/flexserializer/base.rb', line 33 def clear_data self.class._attributes_data = {} end |
#define_attributes ⇒ Object
27 28 29 30 31 |
# File 'lib/flexserializer/base.rb', line 27 def define_attributes clear_data define_default_attrs define_group_attrs end |
#define_default_attrs ⇒ Object
37 38 39 40 |
# File 'lib/flexserializer/base.rb', line 37 def define_default_attrs return if !self.class.data_default_attributes self.class.data_default_attributes.call end |
#define_group_attrs ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/flexserializer/base.rb', line 42 def define_group_attrs p "group_name #{group_name} - inst:#{self.object_id} - #{self.class.object_id}" if !self.class.groups or !self.class.groups.keys.include?(group_name) p "group_name #{group_name} - inst:#{self.object_id} - #{self.class.object_id}" p self.class return end self.class.groups[group_name].each { |block| block.call } end |