Class: ActiveGraphExtensions::Node::Query::QueryProxyEagerLoading::EnhancedTree

Inherits:
ActiveGraph::Node::Query::QueryProxyEagerLoading::AssociationTree
  • Object
show all
Defined in:
lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb

Overview

Tree allowing storage of additional information about the associations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name = nil, rel_length = nil, association_limit = nil) ⇒ EnhancedTree

Returns a new instance of EnhancedTree.



11
12
13
14
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 11

def initialize(model, name = nil, rel_length = nil, association_limit = nil)
  @association_limit = association_limit
  super(model, name, rel_length)
end

Instance Attribute Details

#association_limitObject (readonly)

Returns the value of attribute association_limit.



9
10
11
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 9

def association_limit
  @association_limit
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 9

def options
  @options
end

Instance Method Details

#add_key(key, length = nil, assoc_limit = nil) ⇒ Object



29
30
31
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 29

def add_key(key, length = nil, assoc_limit = nil)
  self[key] ||= self.class.new(model, key, length, assoc_limit)
end

#add_nested(key, value, length = nil, assoc_limit = nil) ⇒ Object



33
34
35
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 33

def add_nested(key, value, length = nil, assoc_limit = nil)
  add_key(key, length, assoc_limit).add_spec(value)
end

#add_spec_and_validate(spec) ⇒ Object



16
17
18
19
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 16

def add_spec_and_validate(spec)
  add_spec(spec)
  validate_for_zero_length_paths
end

#process_hash(spec) ⇒ Object



42
43
44
45
46
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 42

def process_hash(spec)
  spec = spec.dup
  @options = spec.delete(:_options)
  super(spec)
end

#process_string(str) ⇒ Object



37
38
39
40
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 37

def process_string(str)
  map = StringParsers::RelationParser.new.parse(str)
  add_nested(map[:rel_name].to_sym, map[:rest_str].to_s.presence, map[:length_part], map[:limit_digit])
end

#target_class(model, key) ⇒ Object



48
49
50
51
52
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 48

def target_class(model, key)
  association = model.associations[key.to_sym]
  fail "Invalid association: #{[*path, key].join('.')}" unless association
  model.associations[key].target_class
end

#validate_for_zero_length_pathsObject



21
22
23
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 21

def validate_for_zero_length_paths
  fail 'Can not eager load more than one zero length path.' if values.count(&:zero_length_path?) > 1
end

#zero_length_path?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/active_graph_extensions/node/query/query_proxy_eager_loading/enhanced_tree.rb', line 25

def zero_length_path?
  rel_length&.fetch(:min, nil)&.to_s == '0' || values.any?(&:zero_length_path?)
end