geoff 0.0.3.beta → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.6.7.2
data/README.md CHANGED
@@ -1,25 +1,27 @@
1
1
  geoff
2
2
  =====
3
3
 
4
- Geoff is "a declarative notation for representing graph data within concise
5
- human-readable text, designed specifically with Neo4j in mind"
4
+ Geoff is
5
+
6
+ > a declarative notation for representing graph data within concise
7
+ > human-readable text, designed specifically with Neo4j in mind
6
8
 
7
9
  http://geoff.nigelsmall.net/
8
10
 
9
11
 
10
12
  This gem is a Ruby DSL for
11
13
  * generating geoff syntax files
12
- * batch inserting data into Neo4j
14
+ * batch inserting data into [http://neo4j.org/learn/](Neo4j)
13
15
 
14
16
  The reason for creating this gem is to:
15
17
  * easily build data sets for tests
16
18
  * that are readable and maintainable
17
19
  * quickly batch insert the whole data set in one transaction
18
20
 
19
- Prerequesites/ Caveats
21
+ Prerequisites/ Caveats
20
22
  ---------------------
21
23
  * A ruby project
22
- * Gemfile with `gem 'geoff', '0.0.2.beta'`
24
+ * Gemfile with `gem 'geoff', '0.0.3.beta'`
23
25
  * neo4j jar and geoff jar files in lib/jars (not included, but required!)
24
26
  * Current implementation assumes usage of the neo4j wrapper gem
25
27
  * Neo4j::Rails::Model classes or a class that includes the Neo4j::NodeMixin
@@ -29,18 +31,19 @@ Usage
29
31
 
30
32
 
31
33
  ```ruby
34
+ #Gemfile
35
+ gem 'geoff'
32
36
 
33
- #Basic tree like structure for DSL
34
- #the first line generates the class nodes used by Neo4jWrapper
35
37
 
36
- Geoff(Company, Person) do # NB 'Company' and 'Person' are classes with the Neo4j::NodeMixin
38
+ # Basic tree like structure for DSL
39
+ # the first line generates the class nodes used by Neo4jWrapper
40
+ # NB 'Company' and 'Person' are classes with the Neo4j::NodeMixin
41
+ Geoff(Company, Person) do
37
42
  company 'Acme' do
38
43
  address "13 Something Road"
39
44
 
40
45
  children :employees do
41
- person 'Geoff' do
42
- name 'Geoff'
43
- end
46
+ person 'Geoff'
44
47
 
45
48
  person 'Nigel' do
46
49
  name 'Nigel Small'
@@ -60,16 +63,13 @@ end
60
63
  ```
61
64
 
62
65
 
63
- ###Using a ramdisk see http://neo4j.rubyforge.org/guides/configuration.html
66
+ #Configuration
64
67
 
65
- ```sh
66
- diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`
67
- ```
68
68
 
69
69
  ```ruby
70
70
 
71
71
  #in spec helper
72
- Neo4j::Config[:storage_path] = '/Volumes/ramdisk'
72
+ Neo4j::Config[:storage_path] = '/path/to/db'
73
73
 
74
74
  #in rspec
75
75
  before do
@@ -79,12 +79,18 @@ before do
79
79
  end
80
80
  end
81
81
 
82
- #Don't display output, and delete existing database
83
- Geoff::Importer.import geoff, silent: false, delete: true
82
+ #Silence output, and delete existing neo4j db
83
+ Geoff.import geoff, silent: false, delete: true
84
84
  end
85
+ ```
85
86
 
87
+ ###Using a ramdisk see http://neo4j.rubyforge.org/guides/configuration.html
86
88
 
89
+ ```sh
90
+ diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430`
87
91
  ```
92
+
93
+ ```geoff
88
94
  (ROOT)-[:Company]->(Company)
89
95
  (ROOT)-[:Person]->(Person)
90
96
  (Acme) {"_classname":"Company","address":"13 Something Road"}
@@ -121,7 +127,7 @@ Geoff(Company, Person) do
121
127
  end
122
128
  ```
123
129
 
124
- ```
130
+ ```geoff
125
131
  (ROOT)-[:Company]->(Company)
126
132
  (ROOT)-[:Person]->(Person)
127
133
  (Amazon) {"_classname":"Company"}
@@ -154,7 +160,7 @@ Geoff(Company, Person) do
154
160
  end
155
161
  ```
156
162
 
157
- ```
163
+ ```geoff
158
164
  (ROOT)-[:Company]->(Company)
159
165
  (ROOT)-[:Person]->(Person)
160
166
  (Amazon) {"_classname":"Company"}
@@ -171,10 +177,10 @@ end
171
177
  #Using the outer scope
172
178
  ```ruby
173
179
  @hours = SomeFancyAttributeParser.parse <<-EOF
174
- Monday 09:00-15:00
175
- Tuesday 13:00-19:00
176
- Saturday 09:00-16:00
177
- Sunday closed
180
+ Monday 09:00-15:00
181
+ Tuesday 13:00-19:00
182
+ Saturday 09:00-16:00
183
+ Sunday closed
178
184
  EOF
179
185
 
180
186
  Geoff(Company, target: self) do
data/bin/autospec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'autospec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'autospec')
data/bin/coderay ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'coderay' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'coderay')
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'erubis')
data/bin/htmldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'htmldiff')
data/bin/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'ldiff')
data/bin/neo4j-jars ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'neo4j-jars' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'neo4j-jars')
data/bin/neo4j-shell ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'neo4j-shell' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'neo4j-shell')
data/bin/neo4j-upgrade ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'neo4j-upgrade' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'neo4j-upgrade')
data/bin/pry ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'pry' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('pry', 'pry')
data/bin/rackup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'rackup')
data/bin/rails ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'rails')
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'rake')
data/bin/rake2thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake2thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'rake2thor')
data/bin/rdebug ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rdebug' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('ruby-debug', 'rdebug')
data/bin/ri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'ri')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'thor')
data/bin/tilt ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env jruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'tilt' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('geoff', 'tilt')
data/geoff.gemspec CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.homepage = ""
15
15
 
16
16
  gem.files = `git ls-files`.split($\)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
18
  gem.name = "geoff"
20
19
  gem.require_paths = ["lib"]
@@ -1,3 +1,4 @@
1
+ require 'geoff'
1
2
  require 'geoff/node_dsl'
2
3
  require 'geoff/container'
3
4
  require 'geoff/dsl_exception_handling'
@@ -6,8 +7,11 @@ require 'active_support/core_ext/string'
6
7
  class ChildrenDsl
7
8
  include DslExceptionHandling
8
9
 
10
+ attr_reader :node_dsls
11
+ attr_writer :parent_node_dsl
12
+
9
13
  def initialize options, &block
10
- @parent_node_name = options[:parent_node_name]
14
+ @parent_node_dsl = options[:parent_node_dsl]
11
15
  @parent_rel_type = options[:type]
12
16
  @target = options[:target]
13
17
  @outer_geoff = options[:geoff]
@@ -20,6 +24,23 @@ class ChildrenDsl
20
24
  eval_with_exceptions(&block)
21
25
  end
22
26
 
27
+ # Node dsls of children dsl defined inside other children dsl
28
+ # are merged into outer children dsl.
29
+ def children &block
30
+ options = {
31
+ parent_node_dsl: @parent_node_dsl,
32
+ parent_rel_type: @type,
33
+ target: @target,
34
+ outer_geoff: @geoff,
35
+ container: @container
36
+ }
37
+
38
+ children_dsl = ChildrenDsl.new(options, &block) if block_given?
39
+ @node_dsls.merge children_dsl.node_dsls
40
+
41
+ children_dsl
42
+ end
43
+
23
44
  def to_geoff
24
45
  "#{@outer_geoff}\n#{geoff_lines.join("\n")}".strip
25
46
  end
@@ -39,7 +60,7 @@ class ChildrenDsl
39
60
  properties = properties.dup
40
61
  type = properties.delete :type
41
62
 
42
- "(#{@parent_node_name})-[:#{type}]->(#{node_dsl.node_name})".tap do |r|
63
+ "(#{parent_node_name})-[:#{type}]->(#{node_dsl.node_name})".tap do |r|
43
64
  r << " #{properties.to_json}" if properties.any?
44
65
  end
45
66
  end
@@ -50,9 +71,31 @@ class ChildrenDsl
50
71
  end
51
72
 
52
73
  def add_node_dsl node_dsl, rel_properties
74
+ rel_properties ||= {}
75
+ rel_properties[:type] ||= @parent_rel_type
53
76
  @node_dsls[node_dsl] = rel_properties
54
77
  end
55
78
 
79
+ def clone
80
+ c = self.class.new(
81
+ parent_node_dsl: @parent_node_dsl,
82
+ parent_rel_type: @type,
83
+ target: @target,
84
+ outer_geoff: @geoff,
85
+ container: @container
86
+ ) {}
87
+
88
+ node_dsls = {}
89
+ @node_dsls.each do |node_dsl, rel_properties|
90
+ node_dsls[node_dsl.clone] = rel_properties.dup
91
+ end
92
+
93
+ # sort it out, instance_variable_set is probably not the best way to clone object
94
+ c.instance_variable_set('@node_dsls', node_dsls)
95
+
96
+ c
97
+ end
98
+
56
99
  private
57
100
 
58
101
  # e.g.
@@ -101,6 +144,10 @@ class ChildrenDsl
101
144
  end
102
145
 
103
146
  def top_level_node?
104
- @parent_node_name == "ROOT"
147
+ @parent_node_dsl.nil?
148
+ end
149
+
150
+ def parent_node_name
151
+ top_level_node? ? 'ROOT' : @parent_node_dsl.node_name
105
152
  end
106
153
  end
@@ -1,21 +1,61 @@
1
1
  class Container
2
- def initialize validator=nil
3
- @node_dsls = {}
4
- @validator = validator || ->(_, _){}
2
+ attr_reader :node_dsls, :children_dsls
3
+
4
+ def initialize dsls = {}
5
+ @node_dsls = dsls[:node_dsls ] || {}
6
+ @children_dsls = dsls[:children_dsls] || {}
7
+ end
8
+
9
+ def merge other
10
+ @node_dsls .merge! other.node_dsls
11
+ @children_dsls.merge! other.children_dsls
5
12
  end
6
13
 
7
14
  def method_missing m, *args, &blk
8
15
  if m.to_s.last == "=" # assignment
9
- @node_dsls[m.to_s[0..-2]] = args.first
16
+ node_or_children_dsl = args.first
17
+
18
+ # We should only have one dsls hash storing both node dsls and children
19
+ # dsls and methods handle_node_dsl and handle_children_dsl should be
20
+ # moved to corresponding classes.
21
+ if node_or_children_dsl.is_a? NodeDsl
22
+ @node_dsls[m.to_s[0..-2].to_sym] = args.first
23
+ else
24
+ @children_dsls[m.to_s[0..-2].to_sym] = args.first
25
+ end
26
+
27
+ elsif @node_dsls.has_key?(m)
28
+ handle_node_dsl m, *args
29
+
30
+ elsif @children_dsls.has_key?(m)
31
+ handle_children_dsl m, *args
32
+
10
33
  else
11
- node_dsl = @node_dsls[m.to_s]
12
- rel_properties = args.first
13
- @recipient.add_node_dsl node_dsl, rel_properties
14
- node_dsl
34
+ raise Geoff::ContainerLabelMissing, "Container has no key #{m}"
15
35
  end
16
36
  end
17
37
 
18
38
  def set_recipient_of_node_dsl children_dsl
19
39
  @recipient = children_dsl
20
40
  end
41
+
42
+ private
43
+
44
+ def handle_node_dsl m, *args
45
+ node_dsl = @node_dsls[m]
46
+ rel_properties = args.first
47
+ @recipient.add_node_dsl node_dsl, rel_properties
48
+ node_dsl
49
+ end
50
+
51
+ def handle_children_dsl m, *args
52
+ children_dsl = @children_dsls[m]
53
+ rel_properties_override = args.first || {}
54
+
55
+ children_dsl.node_dsls.each do |node_dsl, rel_properties|
56
+ @recipient.add_node_dsl node_dsl.clone, rel_properties.merge(rel_properties_override)
57
+ end
58
+
59
+ children_dsl
60
+ end
21
61
  end
@@ -2,7 +2,7 @@ require 'java'
2
2
  require 'fileutils'
3
3
  Dir["lib/jars/*"].each {|file| require file }
4
4
 
5
- module Geoff
5
+ class Geoff
6
6
  class Error < StandardError ; end
7
7
  class MissingIndexedProperty < Geoff::Error ; end
8
8
  class InvalidRules < Geoff::Error ; end