Class: Flexserializer::Base::DefinitionBuilder
- Inherits:
-
Module
- Object
- Module
- Flexserializer::Base::DefinitionBuilder
- Defined in:
- lib/flexserializer/base.rb
Instance Attribute Summary collapse
-
#attributes_data ⇒ Object
readonly
Returns the value of attribute attributes_data.
-
#reflections ⇒ Object
readonly
Returns the value of attribute reflections.
Instance Method Summary collapse
- #define_attribute(attr, options = {}, &block) ⇒ Object
- #define_attributes(*attrs) ⇒ Object
- #define_belongs_to(name, options = {}, &block) ⇒ Object
- #define_has_many(name, options = {}, &block) ⇒ Object
- #define_has_one(name, options = {}, &block) ⇒ Object
-
#initialize ⇒ DefinitionBuilder
constructor
A new instance of DefinitionBuilder.
Constructor Details
#initialize ⇒ DefinitionBuilder
Returns a new instance of DefinitionBuilder.
8 9 10 11 12 |
# File 'lib/flexserializer/base.rb', line 8 def initialize super() @attributes_data = {} @reflections = {} end |
Instance Attribute Details
#attributes_data ⇒ Object (readonly)
Returns the value of attribute attributes_data.
6 7 8 |
# File 'lib/flexserializer/base.rb', line 6 def attributes_data @attributes_data end |
#reflections ⇒ Object (readonly)
Returns the value of attribute reflections.
6 7 8 |
# File 'lib/flexserializer/base.rb', line 6 def reflections @reflections end |
Instance Method Details
#define_attribute(attr, options = {}, &block) ⇒ Object
21 22 23 24 |
# File 'lib/flexserializer/base.rb', line 21 def define_attribute(attr, = {}, &block) key = .fetch(:key, attr) attributes_data[key] = ActiveModel::Serializer::Attribute.new(attr, , block) end |
#define_attributes(*attrs) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/flexserializer/base.rb', line 14 def define_attributes(*attrs) attrs = attrs.first if attrs.first.class == Array attrs.each do |attr| define_attribute(attr) end end |
#define_belongs_to(name, options = {}, &block) ⇒ Object
30 31 32 |
# File 'lib/flexserializer/base.rb', line 30 def define_belongs_to(name, = {}, &block) define_associate(ActiveModel::Serializer::BelongsToReflection.new(name, , block)) end |
#define_has_many(name, options = {}, &block) ⇒ Object
26 27 28 |
# File 'lib/flexserializer/base.rb', line 26 def define_has_many(name, = {}, &block) define_associate(ActiveModel::Serializer::HasManyReflection.new(name, , block)) end |
#define_has_one(name, options = {}, &block) ⇒ Object
34 35 36 |
# File 'lib/flexserializer/base.rb', line 34 def define_has_one(name, = {}, &block) define_associate(ActiveModel::Serializer::HasOneReflection.new(name, , block)) end |