Module: Roar::Representer::JSON::CollectionJSON::ClassMethods
Defined Under Namespace
Modules: PropertyWithRenderNil, SharedClassMethodsBullshit
Instance Method Summary
collapse
#href, #representable_attrs
Instance Method Details
#items(options = {}, &block) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/roar/representer/json/collection_json.rb', line 108
def items(options={}, &block)
collection :items, { :extend => lambda {|*| representable_attrs.collection_representers[:items] } }.merge!(options)
mod = representable_attrs.collection_representers[:items] = Module.new do
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia
include Roar::Representer::JSON::CollectionJSON::DataMethods
extend SharedClassMethodsBullshit
module_exec(&block)
property :__href, :as => :href
def __href
compile_links_for(representable_attrs.collection_representers[:href].link_configs).first.href
end
def __href=(v)
@__href = Roar::Representer::Feature::Hypermedia::Hyperlink.new(:href => v)
end
def href
@__href
end
end
end
|
#queries(&block) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/roar/representer/json/collection_json.rb', line 94
def queries(&block)
mod = representable_attrs.collection_representers[:queries] = Module.new do
include Roar::Representer::JSON
include Roar::Representer::Feature::Hypermedia
module_exec(&block)
def to_hash(*)
hash = super
hash["links"] end
end
end
|
#template(&block) ⇒ Object
TODO: provide automatic copying from the ItemRepresenter here.
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/roar/representer/json/collection_json.rb', line 63
def template(&block)
mod = representable_attrs.collection_representers[:object_template] = Module.new do
include Roar::Representer::JSON
include Roar::Representer::JSON::CollectionJSON::DataMethods
extend PropertyWithRenderNil
module_exec(&block)
def from_hash(hash, *args) super(hash["template"])
end
end
representable_attrs.collection_representers[:template] = Module.new do
include Roar::Representer::JSON
include mod
def from_hash(hash, *args)
replace(hash["data"])
end
end
end
|
#template_representer ⇒ Object
90
91
92
|
# File 'lib/roar/representer/json/collection_json.rb', line 90
def template_representer
representable_attrs.collection_representers[:object_template]
end
|
#version(v) ⇒ Object
133
134
135
|
# File 'lib/roar/representer/json/collection_json.rb', line 133
def version(v)
representable_attrs.collection_representers[:version] = v
end
|