Module: AbcJsonapi::Serializer::ClassMethods

Defined in:
lib/abc_jsonapi/serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#relationshipsObject (readonly)

Returns the value of attribute relationships.



48
49
50
# File 'lib/abc_jsonapi/serializer.rb', line 48

def relationships
  @relationships
end

#resource_attributesObject (readonly)

Returns the value of attribute resource_attributes.



48
49
50
# File 'lib/abc_jsonapi/serializer.rb', line 48

def resource_attributes
  @resource_attributes
end

#virtual_attributesObject (readonly)

Returns the value of attribute virtual_attributes.



48
49
50
# File 'lib/abc_jsonapi/serializer.rb', line 48

def virtual_attributes
  @virtual_attributes
end

Instance Method Details

#attribute(name, &block) ⇒ Object



70
71
72
# File 'lib/abc_jsonapi/serializer.rb', line 70

def attribute(name, &block)
  @virtual_attributes << { name: name, block: block }
end

#attributes(*attributes) ⇒ Object



50
51
52
# File 'lib/abc_jsonapi/serializer.rb', line 50

def attributes(*attributes)
  @resource_attributes = attributes
end

#belongs_to(relationship, &block) ⇒ Object



62
63
64
# File 'lib/abc_jsonapi/serializer.rb', line 62

def belongs_to(relationship, &block)
  @relationships << { type: :belongs_to, name: relationship, block: block }
end

#has_many(relationship, &block) ⇒ Object



58
59
60
# File 'lib/abc_jsonapi/serializer.rb', line 58

def has_many(relationship, &block)
  @relationships << { type: :has_many, name: relationship, block: block }
end

#has_one(relationship, &block) ⇒ Object



54
55
56
# File 'lib/abc_jsonapi/serializer.rb', line 54

def has_one(relationship, &block)
  @relationships << { type: :has_one, name: relationship, block: block }
end

#resource_type(rtype = nil) ⇒ Object



66
67
68
# File 'lib/abc_jsonapi/serializer.rb', line 66

def resource_type(rtype = nil)
  @resource_type ||= rtype || Helpers.pluralize_if_necessary(default_type)
end