Module: Neo4j::Wrapper::Find
- Defined in:
- lib/neo4j-wrapper/find.rb
Instance Method Summary collapse
-
#_index_name ⇒ String
The name of the index, with index prefix.
-
#find(*query_params, &block) ⇒ Object
Overrides the Neo4j::Core::Index::ClassMethods#find method to check if any of the query parameters needs to be converted, (e.g. DateTime to Fixnum).
-
#index_prefix ⇒ String
If the #ref_node_for_class returns an object implementing the method #_index_prefix it will use that as prefix, otherwise the empty string.
-
#ref_node(&block) ⇒ Object
Assigns the reference node for a class via a supplied block.
-
#ref_node_for_class ⇒ Neo4j::Node
Fall back to the threadlocal ref node by default.
Instance Method Details
#_index_name ⇒ String
Returns the name of the index, with index prefix.
19 20 21 |
# File 'lib/neo4j-wrapper/find.rb', line 19 def _index_name to_s.gsub("::", '_') end |
#find(*query_params, &block) ⇒ Object
Overrides the Neo4j::Core::Index::ClassMethods#find method to check if any of the query parameters needs to be converted, (e.g. DateTime to Fixnum)
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/neo4j-wrapper/find.rb', line 51 def find(*query_params, &block) query = query_params.first if query.is_a?(Hash) query.each_pair do |k, v| converter = _converter(k) value = v.is_a?(Range) ? Range.new(converter.to_java(v.begin), converter.to_java(v.end), v.exclude_end?) : converter.to_java(v) query[k] = value end end _orig_find(*query_params, &block) end |
#index_prefix ⇒ String
If the #ref_node_for_class returns an object implementing the method #_index_prefix it will use that as prefix, otherwise the empty string.
9 10 11 12 13 14 15 |
# File 'lib/neo4j-wrapper/find.rb', line 9 def index_prefix return "" unless Neo4j.running? return "" unless respond_to?(:ref_node_for_class) ref_node = ref_node_for_class.wrapper prefix = ref_node.send(:index_prefix) if ref_node.respond_to?(:index_prefix) prefix ? prefix + "_" : "" end |
#ref_node(&block) ⇒ Object
Assigns the reference node for a class via a supplied block.
38 39 40 41 42 43 |
# File 'lib/neo4j-wrapper/find.rb', line 38 def ref_node(&block) singleton = class << self; self; end singleton.send(:define_method, :ref_node_for_class) { block.call } end |
#ref_node_for_class ⇒ Neo4j::Node
Fall back to the threadlocal ref node by default. You can set your own reference node using the #ref_node method
26 27 28 |
# File 'lib/neo4j-wrapper/find.rb', line 26 def ref_node_for_class Neo4j.ref_node end |