module JSONAPI::Attributes::ClassMethods
Attributes
attributes_map[RW]
to_many_associations[RW]
to_one_associations[RW]
Public Instance Methods
attribute(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 27 def attribute(name, options = {}, &block) add_attribute(name, options, &block) end
attributes(*names)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 31 def attributes(*names) names.each { |name| add_attribute(name) } end
has_many(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 39 def has_many(name, options = {}, &block) add_to_many_association(name, options, &block) end
has_one(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 35 def has_one(name, options = {}, &block) add_to_one_association(name, options, &block) end
Private Instance Methods
add_attribute(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 43 def add_attribute(name, options = {}, &block) # Blocks are optional and can override the default attribute discovery. They are just # stored here, but evaluated by the Serializer within the instance context. @attributes_map ||= {} @attributes_map[name] = { attr_or_block: block_given? ? block : name, options: options, } end
add_to_many_association(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 65 def add_to_many_association(name, options = {}, &block) options[:include_links] = options.fetch(:include_links, true) options[:include_data] = options.fetch(:include_data, false) @to_many_associations ||= {} @to_many_associations[name] = { attr_or_block: block_given? ? block : name, options: options, } end
add_to_one_association(name, options = {}, &block)
click to toggle source
# File lib/jsonapi-serializers/attributes.rb, line 54 def add_to_one_association(name, options = {}, &block) options[:include_links] = options.fetch(:include_links, true) options[:include_data] = options.fetch(:include_data, false) @to_one_associations ||= {} @to_one_associations[name] = { attr_or_block: block_given? ? block : name, options: options, } end