Module: JsonApi::Resources::DSL

Included in:
JsonApi::Resource
Defined in:
lib/json_api_ruby/resources/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_id_fieldObject (readonly)

Returns the value of attribute _id_field.



4
5
6
# File 'lib/json_api_ruby/resources/dsl.rb', line 4

def _id_field
  @_id_field
end

Returns the value of attribute _use_links.



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

def _use_links
  @_use_links
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#relationshipsObject (readonly)

Returns the value of attribute relationships.



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

def relationships
  @relationships
end

Instance Method Details

#attribute(attr) ⇒ Object



15
16
17
18
19
# File 'lib/json_api_ruby/resources/dsl.rb', line 15

def attribute(attr)
  @fields ||= []
  @fields << attr
  create_accessor_methods(attr)
end

#attributes(*attrs) ⇒ Object



9
10
11
12
13
# File 'lib/json_api_ruby/resources/dsl.rb', line 9

def attributes(*attrs)
  attrs.each do |attr|
    attribute(attr)
  end
end

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



25
26
27
# File 'lib/json_api_ruby/resources/dsl.rb', line 25

def has_many(object_name, options={})
  add_relationship(object_name, :many, options)
end

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



21
22
23
# File 'lib/json_api_ruby/resources/dsl.rb', line 21

def has_one(object_name, options={})
  add_relationship(object_name, :one, options)
end

#id_field(key) ⇒ Object



29
30
31
# File 'lib/json_api_ruby/resources/dsl.rb', line 29

def id_field(key)
  @_id_field = key
end


33
34
35
# File 'lib/json_api_ruby/resources/dsl.rb', line 33

def use_links(yesno)
  @_use_links = yesno
end