Module: AbcJsonapi::Serializer::ClassMethods

Defined in:
lib/abc_jsonapi/serializer.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, &block) ⇒ Object



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

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

#attributes(*attributes) ⇒ Object



43
44
45
# File 'lib/abc_jsonapi/serializer.rb', line 43

def attributes(*attributes)
  @resource_attributes = attributes
end

#belongs_to(relationship, &block) ⇒ Object



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

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

#has_many(relationship, &block) ⇒ Object



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

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

#has_one(relationship, &block) ⇒ Object



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

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

#resource_type(rtype = nil) ⇒ Object



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

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