Module: Neo4j::Wrapper::Find

Defined in:
lib/neo4j-wrapper/find.rb

Instance Method Summary (collapse)

Instance Method Details

- (String) _index_name

Returns the name of the index, with index prefix

Returns:

  • (String)

    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

- (Object) find(*query_params, &block)

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)

Examples:

Person.find(:since => (1.year.ago .. Time.now))

See Also:



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

- (String) index_prefix

If the #ref_node_for_class returns an object implementing the method #_index_prefix it will use that as prefix, otherwise the empty string.

Returns:

  • (String)

    the prefix name of the index



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

- (Object) ref_node(&block)

Assigns the reference node for a class via a supplied block.

Examples:

of usage:

class Person
  include Neo4j::NodeMixin
  ref_node { Neo4j.default_ref_node }
end


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

- (Neo4j::Node) ref_node_for_class

Fall back to the threadlocal ref node by default. You can set your own reference node using the #ref_node method

Returns:

  • (Neo4j::Node)

    returns the Neo4j.ref_node



26
27
28
# File 'lib/neo4j-wrapper/find.rb', line 26

def ref_node_for_class
  Neo4j.ref_node
end