neo4j-cypher 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,16 +2,19 @@ module Neo4j
2
2
  module Cypher
3
3
  class Start
4
4
  include Clause
5
- include Referenceable
6
5
 
7
- attr_accessor :entities # TODO CHECK if needed
8
-
9
- def initialize(clause_list)
6
+ def initialize(clause_list, rvalue)
10
7
  super(clause_list, :start, EvalContext)
8
+ @rvalue = rvalue
9
+ end
10
+
11
+ def entity_list(entity_type, entities)
12
+ list = entities.map { |n| n.respond_to?(:neo_id) ? n.neo_id : n }.join(',')
13
+ "#{entity_type}(#{list})"
11
14
  end
12
15
 
13
- def initialize_entities(entities)
14
- @entities = entities.map { |n| n.respond_to?(:neo_id) ? n.neo_id : n }
16
+ def to_cypher
17
+ "#{var_name}=#{@rvalue}"
15
18
  end
16
19
 
17
20
  class EvalContext
@@ -30,63 +33,56 @@ module Neo4j
30
33
  class StartNode < Start
31
34
 
32
35
  def initialize(clause_list, nodes)
33
- super(clause_list)
34
- initialize_entities(nodes)
35
- end
36
-
37
- def to_cypher
38
- "#{var_name}=node(#{entities.join(',')})"
36
+ super(clause_list, entity_list('node', nodes))
39
37
  end
40
-
41
38
  end
42
39
 
43
40
 
44
41
  # Can be created from a <tt>rel</tt> dsl method.
45
42
  class StartRel < Start
46
43
  def initialize(clause_list, rels)
47
- super(clause_list)
48
- initialize_entities(rels)
44
+ super(clause_list, entity_list('relationship', rels))
49
45
  end
46
+ end
50
47
 
51
- def to_cypher
52
- "#{var_name}=relationship(#{entities.join(',')})"
48
+ class LuceneQuery < Start
49
+ def initialize(clause_list, query, type)
50
+ super(clause_list, "#{type}:#{query}")
51
+ end
52
+
53
+ def self._lookup_params(index_class, key, value)
54
+ %Q[#{_index_name_for_key(index_class, key)}(#{key}="#{value}")]
53
55
  end
54
- end
55
56
 
56
- class NodeQuery < Start
57
- attr_reader :index_name, :query
57
+ def self.lookup_node_by_class(clause_list, index_class, key, value)
58
+ LuceneQuery.new(clause_list, _lookup_params(index_class, key, value), 'node')
59
+ end
58
60
 
59
- def initialize(clause_list, index_class, query, index_type)
60
- super(clause_list)
61
- @index_name = index_class.index_name_for_type(index_type)
62
- @query = query
61
+ def self.query_node_by_class(clause_list, index_class, query, index_type)
62
+ LuceneQuery.new(clause_list, "#{_index_name_for_type(index_class, index_type)}(#{query})", 'node')
63
63
  end
64
64
 
65
- def to_cypher
66
- "#{var_name}=node:#{index_name}(#{query})"
65
+ def self.lookup_rel_by_class(clause_list, index_class, key, value)
66
+ LuceneQuery.new(clause_list, _lookup_params(index_class, key, value), 'relationship')
67
+ end
68
+
69
+ def self.query_rel_by_class(clause_list, index_class, query, index_type)
70
+ LuceneQuery.new(clause_list, "#{_index_name_for_type(index_class, index_type)}(#{query})", 'relationship')
67
71
  end
68
- end
69
72
 
70
- class NodeLookup < Start
71
- attr_reader :index_name, :query
73
+ def self._index_name_for_type(index_class , index_type)
74
+ index_class.respond_to?(:index_name_for_type) ? index_class.index_name_for_type(index_type) : index_class.to_s
75
+ end
72
76
 
73
- def initialize(clause_list, index_class, key, value)
74
- super(clause_list)
77
+ def self._index_name_for_key(index_class, key)
75
78
  if index_class.respond_to?(:index_type)
76
79
  index_type = index_class.index_type(key.to_s)
77
80
  raise "No index on #{index_class} property #{key}" unless index_type
78
- @index_name = index_class.index_name_for_type(index_type)
81
+ index_class.index_name_for_type(index_type)
79
82
  else
80
- @index_name = index_class
83
+ index_class.to_s
81
84
  end
82
-
83
- @query = %Q[#{key}="#{value}"]
84
- end
85
-
86
- def to_cypher
87
- %Q[#{var_name}=node:#{index_name}(#{query})]
88
85
  end
89
-
90
86
  end
91
87
 
92
88
  end
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Cypher
3
- VERSION = '1.0.0.rc2'
3
+ VERSION = '1.0.0'
4
4
  end
5
- end
5
+ end
@@ -3,13 +3,26 @@ module Neo4j
3
3
  class Where
4
4
  include Clause
5
5
 
6
- def initialize(clause_list, where_statement = nil)
6
+ def initialize(clause_list, context, where_statement = nil, &block)
7
7
  super(clause_list, :where)
8
- @where_statement = where_statement
8
+
9
+ if where_statement
10
+ @where_statement = where_statement
11
+ else
12
+ clause_list.push
13
+ RootClause::EvalContext.new(context).instance_exec(context, &block)
14
+ @where_statement = clause_list.to_cypher
15
+ clause_list.pop
16
+ end
17
+
18
+ end
19
+
20
+ def neg!
21
+ @where_statement = "not(#{@where_statement})"
9
22
  end
10
23
 
11
24
  def to_cypher
12
- @where_statement.to_s
25
+ @where_statement
13
26
  end
14
27
  end
15
28
  end
@@ -12,12 +12,10 @@ module Neo4j
12
12
 
13
13
  @args = create_clause_args_for(args)
14
14
  @arg_list = @args.map { |a| a.return_value }.join(',')
15
- @where_or_match = where_or_match
16
15
  arg_exec = @args.map(&:eval_context)
17
16
 
18
17
  RootClause::EvalContext.new(self).instance_exec(*arg_exec, &cypher_dsl)
19
-
20
- @body = "#{@where_or_match.to_s.upcase} #{clause_list.to_cypher}"
18
+ @body = "#{where_or_match.to_s.upcase} #{clause_list.to_cypher}"
21
19
  clause_list.pop
22
20
  end
23
21
 
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ #require 'term/ansicolor'
3
+ require 'reek/rake/task'
4
+
5
+ # Stolen rake task from https://github.com/andywenk/ruby_code_analyzer_rake_tasks/blob/master/lib/tasks/analyzer.rake
6
+
7
+ Reek::Rake::Task.new do |t|
8
+ t.source_files = "app"
9
+ t.verbose = false
10
+ t.fail_on_error = false
11
+ end
12
+
13
+ SOURCE_DIR = 'lib/neo4j-cypher/*.rb'
14
+
15
+ namespace :analyzer do
16
+ desc "run all code analyzing tools (reek, rails_best_practices, flog, flay)"
17
+ task :all => [:reek, :flog, :flay] do
18
+ message(:info, 'have been running all code analyzing tools')
19
+ end
20
+
21
+ desc "run reek and find code smells"
22
+ task :reek do
23
+ message(:info, 'Running reek and find code smells')
24
+ Rake::Task['reek'].invoke
25
+ end
26
+
27
+ desc "run flog and find the most tortured code"
28
+ task :flog do
29
+ message(:info, 'Running flog and find the most tortured code')
30
+ sh "flog -ca #{SOURCE_DIR}"
31
+ end
32
+
33
+ desc "run flay and analyze code for structural similarities"
34
+ task :flay do
35
+ message(:info, 'Running flay and and analyze code for structural similarities')
36
+ sh "flay #{SOURCE_DIR}"
37
+ end
38
+ end
39
+
40
+ def message(type, message)
41
+ set_color(type)
42
+ puts message
43
+ reset_color
44
+ end
45
+
46
+ def set_color(type)
47
+ term = Term::ANSIColor
48
+ colors = {info: term.green, error: term.red}
49
+ puts colors[type]
50
+ end
51
+
52
+ def reset_color
53
+ puts Term::ANSIColor.reset
54
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j-cypher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
5
- prerelease: 6
4
+ version: 1.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andreas Ronge
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-21 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'This gem is used in the JRuby neo4j gem but should work on any Ruby
15
15
  implementation since it simply
@@ -23,13 +23,16 @@ extensions: []
23
23
  extra_rdoc_files:
24
24
  - README.rdoc
25
25
  files:
26
+ - lib/neo4j-cypher/abstract_filter.rb
26
27
  - lib/neo4j-cypher/argument.rb
27
28
  - lib/neo4j-cypher/clause.rb
28
29
  - lib/neo4j-cypher/clause_list.rb
30
+ - lib/neo4j-cypher/collection.rb
29
31
  - lib/neo4j-cypher/context.rb
30
32
  - lib/neo4j-cypher/create.rb
33
+ - lib/neo4j-cypher/foreach.rb
31
34
  - lib/neo4j-cypher/match.rb
32
- - lib/neo4j-cypher/mixins.rb
35
+ - lib/neo4j-cypher/neography.rb
33
36
  - lib/neo4j-cypher/node_var.rb
34
37
  - lib/neo4j-cypher/operator.rb
35
38
  - lib/neo4j-cypher/predicate.rb
@@ -44,6 +47,7 @@ files:
44
47
  - lib/neo4j-cypher/where.rb
45
48
  - lib/neo4j-cypher/with.rb
46
49
  - lib/neo4j-cypher.rb
50
+ - lib/tasks/analyzer.rake
47
51
  - README.rdoc
48
52
  - Gemfile
49
53
  - neo4j-cypher.gemspec
@@ -69,9 +73,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
73
  required_rubygems_version: !ruby/object:Gem::Requirement
70
74
  none: false
71
75
  requirements:
72
- - - ! '>'
76
+ - - ! '>='
73
77
  - !ruby/object:Gem::Version
74
- version: 1.3.1
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -2728689632116511744
75
82
  requirements: []
76
83
  rubyforge_project: neo4j-cypher
77
84
  rubygems_version: 1.8.24
@@ -1,47 +0,0 @@
1
- module Neo4j
2
- module Cypher
3
- module Referenceable
4
- def var_name
5
- @var_name ||= @clause_list.create_variable(self)
6
- end
7
-
8
- def var_name=(new_name)
9
- @var_name = new_name.to_sym
10
- end
11
-
12
- def referenced?
13
- !!@referenced
14
- end
15
-
16
- def referenced!
17
- @referenced = true
18
- end
19
-
20
- def as_alias(new_name)
21
- @alias = new_name
22
- self.var_name = new_name
23
- end
24
-
25
- def alias_name
26
- @alias
27
- end
28
-
29
- def as_alias?
30
- !!@alias && var_name != return_value
31
- end
32
-
33
- end
34
-
35
- module ToPropString
36
- def to_prop_string(props)
37
- key_values = props.keys.map do |key|
38
- raw = key.to_s[0, 1] == '_'
39
- val = props[key].is_a?(String) && !raw ? "'#{props[key]}'" : props[key]
40
- "#{raw ? key.to_s[1..-1] : key} : #{val}"
41
- end
42
- "{#{key_values.join(', ')}}"
43
- end
44
- end
45
-
46
- end
47
- end