Class: NoSE::Connection
- Includes:
- StatementSupportQuery
- Defined in:
- lib/nose/statements/connection.rb
Overview
Superclass for connect and disconnect statements
Direct Known Subclasses
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#source_pk ⇒ Object
readonly
Returns the value of attribute source_pk.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#target_pk ⇒ Object
readonly
Returns the value of attribute target_pk.
Attributes inherited from Statement
#comment, #entity, #eq_fields, #graph, #group, #key_path, #label, #range_field, #text
Class Method Summary collapse
-
.keys_from_tree(tree, params) ⇒ Object
@return.
-
.parse(tree, params, text, group: nil, label: nil) ⇒ Connection
Build a new disconnect from a provided parse tree.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(params, text, group: nil, label: nil) ⇒ Connection
constructor
A new instance of Connection.
-
#modifies_index?(index) ⇒ Boolean
A connection modifies an index if the relationship is in the path.
-
#support_queries(index) ⇒ Object
Get the support queries for updating an index.
-
#unparse ⇒ String
Produce the SQL text corresponding to this connection.
Methods inherited from Statement
#materialize_view, #read_only?, #requires_delete?, #requires_insert?, #to_color
Constructor Details
#initialize(params, text, group: nil, label: nil) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 |
# File 'lib/nose/statements/connection.rb', line 11 def initialize(params, text, group: nil, label: nil) super params, text, group: group, label: label fail InvalidStatementException, 'Incorrect connection initialization' \ unless text.split.first == self.class.name.split('::').last.upcase populate_conditions params end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
8 9 10 |
# File 'lib/nose/statements/connection.rb', line 8 def conditions @conditions end |
#source_pk ⇒ Object (readonly)
Returns the value of attribute source_pk.
8 9 10 |
# File 'lib/nose/statements/connection.rb', line 8 def source_pk @source_pk end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/nose/statements/connection.rb', line 8 def target @target end |
#target_pk ⇒ Object (readonly)
Returns the value of attribute target_pk.
8 9 10 |
# File 'lib/nose/statements/connection.rb', line 8 def target_pk @target_pk end |
Class Method Details
.keys_from_tree(tree, params) ⇒ Object
28 29 30 31 32 |
# File 'lib/nose/statements/connection.rb', line 28 def self.keys_from_tree(tree, params) params[:source_pk] = tree[:source_pk] params[:target] = params[:entity].foreign_keys[tree[:target].to_s] params[:target_pk] = tree[:target_pk] end |
.parse(tree, params, text, group: nil, label: nil) ⇒ Connection
Build a new disconnect from a provided parse tree
21 22 23 24 25 |
# File 'lib/nose/statements/connection.rb', line 21 def self.parse(tree, params, text, group: nil, label: nil) keys_from_tree tree, params new params, text, group: group, label: label end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
41 42 43 44 45 46 47 |
# File 'lib/nose/statements/connection.rb', line 41 def ==(other) self.class == other.class && @graph == other.graph && @source == other.source && @target == other.target && @conditions == other.conditions end |
#hash ⇒ Object
50 51 52 |
# File 'lib/nose/statements/connection.rb', line 50 def hash @hash ||= [@graph, @source, @target, @conditions].hash end |
#modifies_index?(index) ⇒ Boolean
A connection modifies an index if the relationship is in the path
55 56 57 |
# File 'lib/nose/statements/connection.rb', line 55 def modifies_index?(index) index.path.include?(@target) || index.path.include?(@target.reverse) end |
#support_queries(index) ⇒ Object
Get the support queries for updating an index
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nose/statements/connection.rb', line 60 def support_queries(index) return [] unless modifies_index?(index) select = index.all_fields - @conditions.each_value.map(&:field).to_set return [] if select.empty? index.graph.split(entity).map do |graph| support_fields = select.select do |field| graph.entities.include? field.parent end.to_set conditions = @conditions.select do |_, c| graph.entities.include? c.field.parent end split_entity = split_entity graph, index.graph, entity build_support_query split_entity, index, graph, support_fields, conditions end.compact end |
#unparse ⇒ String
Produce the SQL text corresponding to this connection
36 37 38 39 |
# File 'lib/nose/statements/connection.rb', line 36 def unparse "CONNECT #{source.name}(\"#{source_pk}\") TO " \ "#{target.name}(\"#{target_pk}\")" end |