Class: JsonapiCompliable::Scope
- Inherits:
-
Object
- Object
- JsonapiCompliable::Scope
- Defined in:
- lib/jsonapi_compliable/scope.rb
Instance Method Summary collapse
-
#initialize(object, resource, query, opts = {}) ⇒ Scope
constructor
A new instance of Scope.
- #query_hash ⇒ Object
- #resolve ⇒ Object
- #resolve_stats ⇒ Object
Constructor Details
#initialize(object, resource, query, opts = {}) ⇒ Scope
Returns a new instance of Scope.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/jsonapi_compliable/scope.rb', line 3 def initialize(object, resource, query, opts = {}) @object = object @resource = resource @query = query # Namespace for the 'outer' or 'main' resource is its type # For its relationships, its the relationship name # IOW when hitting /states, it's resource type 'states # when hitting /authors?include=state its 'state' @namespace = opts.delete(:namespace) || resource.type apply_scoping(opts) end |
Instance Method Details
#query_hash ⇒ Object
31 32 33 |
# File 'lib/jsonapi_compliable/scope.rb', line 31 def query_hash @query_hash ||= @query.to_hash[@namespace] end |
#resolve ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/jsonapi_compliable/scope.rb', line 21 def resolve if @query.zero_results? [] else resolved = @resource.resolve(@object) sideload(resolved, query_hash[:include]) if query_hash[:include] resolved end end |