lib/roar/json/json_api.rb in roar-1.0.0 vs lib/roar/json/json_api.rb in roar-1.0.1
- old
+ new
@@ -20,11 +20,11 @@
module ForCollection
def for_collection # same API as representable. TODO: we could use ::collection_representer! here.
singular = self # e.g. Song::Representer
# this basically does Module.new { include Hash::Collection .. }
- build_inline(nil, [Document::Collection, Representable::Hash::Collection, Roar::JSON], "", {}) do
+ build_inline(nil, [Representable::Hash::Collection, Document::Collection, Roar::JSON], "", {}) do
items extend: singular, :parse_strategy => :sync
representable_attrs[:resource_representer] = singular.representable_attrs[:resource_representer]
representable_attrs[:meta_representer] = singular.representable_attrs[:meta_representer] # DISCUSS: do we need that?
representable_attrs[:_wrap] = singular.representable_attrs[:_wrap]
@@ -34,11 +34,11 @@
module Singular
def to_hash(options={})
# per resource:
- super(:exclude => [:links]).tap do |hash|
+ super(options.merge(:exclude => [:links])).tap do |hash|
hash["links"] = hash.delete("_links") if hash["_links"]
end
end
def from_hash(hash, options={})
@@ -79,10 +79,10 @@
representable_attrs[:resource_representer].link(*args, &block)
end
# Per-model links.
def links(&block)
- nested(:_links, &block)
+ nested(:_links, :inherit => true, &block)
end
# TODO: always create _links.
def has_one(name)
property :_links, :inherit => true, :use_decorator => true do # simply extend the Decorator _links.