Module: SimpleJsonApi::DSL

Included in:
Serializer
Defined in:
lib/simple_json_api/dsl.rb

Overview

Define the public API for creating serializers

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_associationsObject

Returns the value of attribute _associations.



5
6
7
# File 'lib/simple_json_api/dsl.rb', line 5

def _associations
  @_associations
end

#_attributesObject

Returns the value of attribute _attributes.



6
7
8
# File 'lib/simple_json_api/dsl.rb', line 6

def _attributes
  @_attributes
end

#_root_nameObject (readonly)

Returns the value of attribute _root_name.



7
8
9
# File 'lib/simple_json_api/dsl.rb', line 7

def _root_name
  @_root_name
end

Instance Method Details

#attribute(name, options = {}) ⇒ Object



22
23
24
# File 'lib/simple_json_api/dsl.rb', line 22

def attribute(name, options = {})
  register_attribute(name, options)
end

#belongs_to(name, options = {}) ⇒ Object



26
27
28
# File 'lib/simple_json_api/dsl.rb', line 26

def belongs_to(name, options = {})
  register_association(name, :belongs_to, options)
end

#default_fieldsObject



38
39
40
# File 'lib/simple_json_api/dsl.rb', line 38

def default_fields
  @_attributes.map(&:first).join(',')
end

#has_many(name, options = {}) ⇒ Object



30
31
32
# File 'lib/simple_json_api/dsl.rb', line 30

def has_many(name, options = {})
  register_association(name, :has_many, options)
end

#has_one(name, options = {}) ⇒ Object



34
35
36
# File 'lib/simple_json_api/dsl.rb', line 34

def has_one(name, options = {})
  register_association(name, :has_one, options)
end

#inherited(base) ⇒ Object



9
10
11
12
# File 'lib/simple_json_api/dsl.rb', line 9

def inherited(base)
  base._associations = []
  base._attributes = []
end

#serializes(name, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/simple_json_api/dsl.rb', line 14

def serializes(name, options = {})
  ResourceSerializer.register_serializer(
    { serializer: self, resource: name },
    options
  )
  @_root_name = name
end