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.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_data ⇒ Object
- #define_attributes(group) ⇒ Object
- #define_default_attrs ⇒ Object
- #define_group_attrs(group) ⇒ Object
-
#initialize(object, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(object, options = {}) ⇒ Base
Returns a new instance of Base.
16 17 18 19 |
# File 'lib/flexserializer/base.rb', line 16 def initialize(object, = {}) define_attributes([:group]) 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 |
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 |
# File 'lib/flexserializer/base.rb', line 10 def group(*group_names, &block) self.groups ||= {} group_names.each { |group_name| self.groups[group_name] = block } end |
Instance Method Details
#clear_data ⇒ Object
27 28 29 |
# File 'lib/flexserializer/base.rb', line 27 def clear_data self.class._attributes_data = {} end |
#define_attributes(group) ⇒ Object
21 22 23 24 25 |
# File 'lib/flexserializer/base.rb', line 21 def define_attributes(group) clear_data define_default_attrs define_group_attrs(group) end |
#define_default_attrs ⇒ Object
31 32 33 34 |
# File 'lib/flexserializer/base.rb', line 31 def define_default_attrs return if !self.class.data_default_attributes self.class.data_default_attributes.call end |
#define_group_attrs(group) ⇒ Object
36 37 38 39 |
# File 'lib/flexserializer/base.rb', line 36 def define_group_attrs(group) return if !self.class.groups or !self.class.groups.keys.include?(group) self.class.groups[group].call end |