Class: JsonapiCompliable::Scoping::Base
- Inherits:
-
Object
- Object
- JsonapiCompliable::Scoping::Base
- Defined in:
- lib/jsonapi_compliable/scoping/base.rb
Instance Attribute Summary collapse
-
#query_hash ⇒ Object
readonly
Returns the value of attribute query_hash.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #apply ⇒ Object
- #apply? ⇒ Boolean
- #apply_custom_scope ⇒ Object
- #apply_standard_or_override ⇒ Object
- #apply_standard_scope ⇒ Object
- #apply_standard_scope? ⇒ Boolean
-
#initialize(resource, query_hash, scope, opts = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(resource, query_hash, scope, opts = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 6 def initialize(resource, query_hash, scope, opts = {}) @query_hash = query_hash @resource = resource @scope = scope @opts = opts end |
Instance Attribute Details
#query_hash ⇒ Object (readonly)
Returns the value of attribute query_hash.
4 5 6 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 4 def query_hash @query_hash end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 4 def resource @resource end |
Instance Method Details
#apply ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 13 def apply if apply? apply_standard_or_override else @scope end end |
#apply? ⇒ Boolean
21 22 23 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 21 def apply? true end |
#apply_custom_scope ⇒ Object
43 44 45 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 43 def apply_custom_scope raise 'override in subclass' end |
#apply_standard_or_override ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 25 def apply_standard_or_override if apply_standard_scope? @scope = apply_standard_scope else @scope = apply_custom_scope end @scope end |
#apply_standard_scope ⇒ Object
39 40 41 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 39 def apply_standard_scope raise 'override in subclass' end |
#apply_standard_scope? ⇒ Boolean
35 36 37 |
# File 'lib/jsonapi_compliable/scoping/base.rb', line 35 def apply_standard_scope? custom_scope.nil? end |