Module: Roar::JSON::JSONAPI::Resource::Declarative
- Defined in:
- lib/roar/json/json_api.rb
Overview
New API for JSON-API representers.
Instance Method Summary collapse
- #compound(&block) ⇒ Object
- #has_many(name) ⇒ Object
-
#has_one(name) ⇒ Object
TODO: always create _links.
-
#link(*args, &block) ⇒ Object
Define global document links for the links: directive.
-
#links(&block) ⇒ Object
Per-model links.
- #meta(&block) ⇒ Object
- #type(name = nil) ⇒ Object
Instance Method Details
#compound(&block) ⇒ Object
105 106 107 |
# File 'lib/roar/json/json_api.rb', line 105 def compound(&block) nested(:linked, &block) end |
#has_many(name) ⇒ Object
99 100 101 102 103 |
# File 'lib/roar/json/json_api.rb', line 99 def has_many(name) property :_links, :inherit => true, :use_decorator => true do # simply extend the Decorator _links. collection "#{name.to_s.sub(/s$/, "")}_ids", :as => name end end |
#has_one(name) ⇒ Object
TODO: always create _links.
93 94 95 96 97 |
# File 'lib/roar/json/json_api.rb', line 93 def has_one(name) property :_links, :inherit => true, :use_decorator => true do # simply extend the Decorator _links. property "#{name}_id", :as => name end end |
#link(*args, &block) ⇒ Object
Define global document links for the links: directive.
83 84 85 |
# File 'lib/roar/json/json_api.rb', line 83 def link(*args, &block) representable_attrs[:resource_representer].link(*args, &block) end |
#links(&block) ⇒ Object
Per-model links.
88 89 90 |
# File 'lib/roar/json/json_api.rb', line 88 def links(&block) nested(:_links, :inherit => true, &block) end |
#meta(&block) ⇒ Object
109 110 111 |
# File 'lib/roar/json/json_api.rb', line 109 def (&block) representable_attrs[:meta_representer] = Class.new(Roar::Decorator, &block) end |
#type(name = nil) ⇒ Object
77 78 79 80 |
# File 'lib/roar/json/json_api.rb', line 77 def type(name=nil) return super unless name # original name. representable_attrs[:_wrap] = name.to_s end |