Module: Roar::JSON::JSONAPI::Declarative
- Defined in:
- lib/roar/json/json_api/declarative.rb
Overview
Declarative API for JSON API Representers.
Instance Method Summary collapse
-
#attributes(&block) ⇒ Object
Define attributes for this resource.
-
#has_many(name, options = {}, &block) ⇒ Object
Define a to-many relationship for this resource.
-
#has_one(name, options = {}, &block) ⇒ Object
Define a to-one relationship for this resource.
-
#link(name, options = {}) {|opts| ... } ⇒ Object
Define a link.
-
#meta(options = {}, &block) ⇒ Object
Define meta information.
-
#relationship(&block) ⇒ Object
Define links and meta information for a given relationship.
-
#type(name = nil) ⇒ String
Defjne a type for this resource.
Instance Method Details
#attributes(&block) ⇒ Object
Define attributes for this resource.
36 37 38 |
# File 'lib/roar/json/json_api/declarative.rb', line 36 def attributes(&block) nested(:attributes, inherit: true, &block) end |
#has_many(name, options = {}, &block) ⇒ Object
Define a to-many relationship for this resource.
129 130 131 |
# File 'lib/roar/json/json_api/declarative.rb', line 129 def has_many(name, = {}, &block) has_relationship(name, .merge(collection: true), &block) end |
#has_one(name, options = {}, &block) ⇒ Object
Define a to-one relationship for this resource.
119 120 121 |
# File 'lib/roar/json/json_api/declarative.rb', line 119 def has_one(name, = {}, &block) has_relationship(name, .merge(collection: false), &block) end |
#link(name, options = {}) {|opts| ... } ⇒ Object
Define a link.
61 62 63 64 |
# File 'lib/roar/json/json_api/declarative.rb', line 61 def link(name, = {}, &block) return super(name, &block) unless [:toplevel] for_collection.link(name, &block) end |
#meta(options = {}, &block) ⇒ Object
Define meta information.
83 84 85 86 |
# File 'lib/roar/json/json_api/declarative.rb', line 83 def ( = {}, &block) return super(&block) unless [:toplevel] for_collection.(&block) end |
#relationship(&block) ⇒ Object
Define links and meta information for a given relationship.
101 102 103 104 105 106 |
# File 'lib/roar/json/json_api/declarative.rb', line 101 def relationship(&block) return (@relationship ||= -> {}) unless block heritage.record(:relationship, &block) @relationship = block end |
#type(name = nil) ⇒ String
Defjne a type for this resource.
18 19 20 21 22 23 |
# File 'lib/roar/json/json_api/declarative.rb', line 18 def type(name = nil) return @type unless name # original name. heritage.record(:type, name) @type = name.to_s end |