Module: AbcJsonapi::Serializer::ClassMethods

Defined in:
lib/abc_jsonapi/serializer.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, &block) ⇒ Object



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

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

#attributes(*attributes) ⇒ Object



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

def attributes(*attributes)
  @resource_attributes = attributes
end

#belongs_to(relationship, &block) ⇒ Object



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

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

#has_many(relationship, &block) ⇒ Object



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

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

#has_one(relationship, &block) ⇒ Object



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

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

#resource_type(rtype = nil) ⇒ Object



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

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