Class: Graphiti::ActiveGraph::JsonapiExt::IncludeDirective
- Inherits:
-
JSONAPI::IncludeDirective
- Object
- JSONAPI::IncludeDirective
- Graphiti::ActiveGraph::JsonapiExt::IncludeDirective
- Defined in:
- lib/graphiti/active_graph/jsonapi_ext/include_directive.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
-
#retain_rel_limit ⇒ Object
Returns the value of attribute retain_rel_limit.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_self_reference(key, length) ⇒ Object
- #descend(key) ⇒ Object
- #get ⇒ Object
-
#initialize(include_args, options = {}) ⇒ IncludeDirective
constructor
A new instance of IncludeDirective.
- #key?(key) ⇒ Boolean
- #keys ⇒ Object
- #to_hash ⇒ Object
- #valid_length? ⇒ Boolean
Constructor Details
#initialize(include_args, options = {}) ⇒ IncludeDirective
5 6 7 8 9 10 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 5 def initialize(include_args, = {}) include_hash = JSONAPI::IncludeDirective::Parser.parse_include_args(include_args) @retain_rel_limit = .delete(:retain_rel_limit) @hash = formulate_hash(include_hash, ) = end |
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
3 4 5 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 3 def length @length end |
#retain_rel_limit ⇒ Object
Returns the value of attribute retain_rel_limit.
3 4 5 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 3 def retain_rel_limit @retain_rel_limit end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 22 def [](key) super&.descend(key) || {} end |
#add_self_reference(key, length) ⇒ Object
41 42 43 44 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 41 def add_self_reference(key, length) @hash = @hash.merge(key => self) self.length = length end |
#descend(key) ⇒ Object
26 27 28 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 26 def descend(key) length && length != '' ? dup.tap { |dup| dup.add_self_reference(key, length.to_i - 1) } : self end |
#get ⇒ Object
16 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 16 alias get [] |
#key?(key) ⇒ Boolean
18 19 20 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 18 def key?(key) super && get(key).valid_length? end |
#keys ⇒ Object
12 13 14 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 12 def keys super.select(&method(:key?)) end |
#to_hash ⇒ Object
34 35 36 37 38 39 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 34 def to_hash @hash.each_with_object({}) do |(key, value), hash| key = "#{key}*#{value.length}".to_sym if value.length hash[key] = value.to_hash unless value == self end end |
#valid_length? ⇒ Boolean
30 31 32 |
# File 'lib/graphiti/active_graph/jsonapi_ext/include_directive.rb', line 30 def valid_length? length.nil? || length == '' || length.to_i.positive? end |