Class: Neo4j::Core::QueryClauses::Clause
- Inherits:
-
Object
- Object
- Neo4j::Core::QueryClauses::Clause
- Includes:
- CypherTranslator
- Defined in:
- lib/neo4j-core/query_clauses.rb
Direct Known Subclasses
CreateClause, DeleteClause, LimitClause, MatchClause, OrderClause, RemoveClause, ReturnClause, SetClause, SkipClause, StartClause, UnwindClause, UsingClause, WhereClause, WithClause
Constant Summary
Constants included from CypherTranslator
CypherTranslator::SANITIZE_ESCAPED_REGEXP
Class Attribute Summary collapse
-
.keyword ⇒ Object
readonly
Returns the value of attribute keyword.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #from_string(value) ⇒ Object
-
#initialize(arg, options = {}) ⇒ Clause
constructor
A new instance of Clause.
- #node_from_key_and_value(key, value, options = {}) ⇒ Object
- #value ⇒ Object
Methods included from CypherTranslator
#cypher_prop_list, #escape_quotes, #escape_value, #sanitize_escape_sequences, sanitized_column_names, translate_response
Constructor Details
#initialize(arg, options = {}) ⇒ Clause
Returns a new instance of Clause.
18 19 20 21 22 |
# File 'lib/neo4j-core/query_clauses.rb', line 18 def initialize(arg, = {}) @arg = arg @options = @params = {} end |
Class Attribute Details
.keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
98 99 100 |
# File 'lib/neo4j-core/query_clauses.rb', line 98 def keyword @keyword end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
16 17 18 |
# File 'lib/neo4j-core/query_clauses.rb', line 16 def params @params end |
Class Method Details
.from_args(args, options = {}) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/neo4j-core/query_clauses.rb', line 100 def from_args(args, = {}) args.flatten.map do |arg| if !arg.respond_to?(:empty?) || !arg.empty? self.new(arg, ) end end.compact end |
.to_cypher(clauses) ⇒ Object
108 109 110 |
# File 'lib/neo4j-core/query_clauses.rb', line 108 def to_cypher(clauses) "#{@keyword} #{clause_string(clauses)}" end |
Instance Method Details
#from_string(value) ⇒ Object
56 57 58 |
# File 'lib/neo4j-core/query_clauses.rb', line 56 def from_string(value) value end |
#node_from_key_and_value(key, value, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/neo4j-core/query_clauses.rb', line 60 def node_from_key_and_value(key, value, = {}) prefer = [:prefer] || :var var, label_string, attributes_string = nil case value when String, Symbol var = key label_string = value when Hash if !value.values.any? {|v| v.is_a?(Hash) } case prefer when :var var = key when :label label_string = key end else var = key end if value.size == 1 && value.values.first.is_a?(Hash) label_string, attributes = value.first attributes_string = attributes_string(attributes) else attributes_string = attributes_string(value) end when Class, Module var = key label_string = defined?(value::CYPHER_LABEL) ? value::CYPHER_LABEL : value.name else raise ArgError.new(value) end "(#{var}#{format_label(label_string)}#{attributes_string})" end |
#value ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/neo4j-core/query_clauses.rb', line 24 def value if @arg.is_a?(String) self.from_string @arg elsif @arg.is_a?(Symbol) && self.respond_to?(:from_symbol) self.from_symbol @arg elsif @arg.is_a?(Integer) && self.respond_to?(:from_integer) self.from_integer @arg elsif @arg.is_a?(Hash) if self.respond_to?(:from_hash) self.from_hash @arg elsif self.respond_to?(:from_key_and_value) @arg.map do |key, value| self.from_key_and_value key, value end else raise ArgError.new end else raise ArgError.new end rescue ArgError => arg_error = "Invalid argument for #{self.class.keyword}. Full arguments: #{@arg.inspect}" += " | Invalid part: #{arg_error.arg_part.inspect}" if arg_error.arg_part raise ArgumentError, end |