Module: Jat::Plugins::JsonApi::ClassMethods
- Defined in:
- lib/jat/plugins/json_api/json_api.rb
Instance Method Summary collapse
-
#added_document_meta ⇒ Object
Top-level document meta.
-
#added_object_meta ⇒ Object
Object meta.
-
#added_relationship_meta ⇒ Object
Relationship meta.
- #document_link(name, **opts, &block) ⇒ Object
-
#document_links ⇒ Object
Top-level document links.
- #document_meta(name, **opts, &block) ⇒ Object
- #get_id ⇒ Object
- #get_type ⇒ Object
- #id(**opts, &block) ⇒ Object
- #inherited(subclass) ⇒ Object
- #jsonapi(name, **opts, &block) ⇒ Object
-
#jsonapi_data(_value = nil) ⇒ Object
JSON API block values.
- #map(context) ⇒ Object
- #map_exposed ⇒ Object
- #map_full ⇒ Object
- #object_link(name, **opts, &block) ⇒ Object
-
#object_links ⇒ Object
Links related to the resource.
- #object_meta(name, **opts, &block) ⇒ Object
- #relationship_link(name, **opts, &block) ⇒ Object
-
#relationship_links ⇒ Object
Relationship links.
- #relationship_meta(name, **opts, &block) ⇒ Object
- #type(new_type) ⇒ Object
Instance Method Details
#added_document_meta ⇒ Object
Top-level document meta
214 215 216 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 214 def @added_document_meta ||= {} end |
#added_object_meta ⇒ Object
Object meta
202 203 204 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 202 def @added_object_meta ||= {} end |
#added_relationship_meta ⇒ Object
Relationship meta
226 227 228 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 226 def @added_relationship_meta ||= {} end |
#document_link(name, **opts, &block) ⇒ Object
182 183 184 185 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 182 def document_link(name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) document_links[new_attr.name] = new_attr end |
#document_links ⇒ Object
Top-level document links
178 179 180 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 178 def document_links @document_links ||= {} end |
#document_meta(name, **opts, &block) ⇒ Object
218 219 220 221 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 218 def (name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) [new_attr.name] = new_attr end |
#get_id ⇒ Object
143 144 145 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 143 def get_id @id end |
#get_type ⇒ Object
135 136 137 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 135 def get_type (defined?(@type) && @type) || raise(Error, "#{self} has no defined type") end |
#id(**opts, &block) ⇒ Object
147 148 149 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 147 def id(**opts, &block) @id = self::Attribute.new(name: :id, opts: opts, block: block) end |
#inherited(subclass) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 66 def inherited(subclass) super fields_parser_class = Class.new(self::FieldsParamParser) fields_parser_class.jat_class = subclass subclass.const_set(:FieldsParamParser, fields_parser_class) includes_parser_class = Class.new(self::IncludeParamParser) includes_parser_class.jat_class = subclass subclass.const_set(:IncludeParamParser, includes_parser_class) map_class = Class.new(self::Map) map_class.jat_class = subclass subclass.const_set(:Map, map_class) response_class = Class.new(self::Response) response_class.jat_class = subclass subclass.const_set(:Response, response_class) response_piece_class = Class.new(self::ResponsePiece) response_piece_class.jat_class = subclass subclass.const_set(:ResponsePiece, response_piece_class) subclass.type(@type) if defined?(@type) subclass.id(&get_id.params[:block]) # Assign same jsonapi_data jsonapi_data.each_value do |attribute| params = attribute.params subclass.jsonapi(params[:name], **params[:opts], ¶ms[:block]) end # Assign same object_links object_links.each_value do |attribute| params = attribute.params subclass.object_link(params[:name], **params[:opts], ¶ms[:block]) end # Assign same document_links document_links.each_value do |attribute| params = attribute.params subclass.document_link(params[:name], **params[:opts], ¶ms[:block]) end # Assign same relationship_links relationship_links.each_value do |attribute| params = attribute.params subclass.relationship_link(params[:name], **params[:opts], ¶ms[:block]) end # Assign same added_object_meta .each_value do |attribute| params = attribute.params subclass.(params[:name], **params[:opts], ¶ms[:block]) end # Assign same added_document_meta .each_value do |attribute| params = attribute.params subclass.(params[:name], **params[:opts], ¶ms[:block]) end # Assign same added_relationship_meta .each_value do |attribute| params = attribute.params subclass.(params[:name], **params[:opts], ¶ms[:block]) end end |
#jsonapi(name, **opts, &block) ⇒ Object
158 159 160 161 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 158 def jsonapi(name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) jsonapi_data[new_attr.name] = new_attr end |
#jsonapi_data(_value = nil) ⇒ Object
JSON API block values
154 155 156 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 154 def jsonapi_data(_value = nil) @jsonapi_data ||= {} end |
#map(context) ⇒ Object
235 236 237 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 235 def map(context) self::Map.call(context) end |
#map_exposed ⇒ Object
243 244 245 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 243 def map_exposed @map_exposed ||= self::Map.call(exposed: :default) end |
#map_full ⇒ Object
239 240 241 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 239 def map_full @map_full ||= self::Map.call(exposed: :all) end |
#object_link(name, **opts, &block) ⇒ Object
170 171 172 173 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 170 def object_link(name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) object_links[new_attr.name] = new_attr end |
#object_links ⇒ Object
Links related to the resource
166 167 168 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 166 def object_links @object_links ||= {} end |
#object_meta(name, **opts, &block) ⇒ Object
206 207 208 209 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 206 def (name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) [new_attr.name] = new_attr end |
#relationship_link(name, **opts, &block) ⇒ Object
194 195 196 197 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 194 def relationship_link(name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) relationship_links[new_attr.name] = new_attr end |
#relationship_links ⇒ Object
Relationship links
190 191 192 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 190 def relationship_links @relationship_links ||= {} end |
#relationship_meta(name, **opts, &block) ⇒ Object
230 231 232 233 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 230 def (name, **opts, &block) new_attr = self::Attribute.new(name: name, opts: opts, block: block) [new_attr.name] = new_attr end |
#type(new_type) ⇒ Object
139 140 141 |
# File 'lib/jat/plugins/json_api/json_api.rb', line 139 def type(new_type) @type = new_type.to_sym end |