neo4j_helper 0.1.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ #gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ #gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+
11
+ PLATFORMS
12
+ java
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.6.4)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Peter Ehrlich
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # neo4j_helper
2
+
3
+ This is an add-on library to https://github.com/andreasronge/neo4j
4
+
5
+ I was just using mongoid, and it was great because you could throw anything at it and have it work. This is an
6
+ attempt to bring rails neo4j to the same accomplishment.
7
+
8
+ Read the source, its educational.
9
+
10
+
11
+ gem install neo4j_helper
12
+
13
+
14
+ ## Usage
15
+
16
+ Methods are automatically added to Neo4j::Rails::Model. This means once you install the gem, you can't get away from them. If this causes issues, let me know, and maybe we can implement a mixin instead.
17
+
18
+
19
+ ### Automatic JSON serialization
20
+
21
+ # user.rb
22
+ property :facebook_credentials, :type => :serialize
23
+
24
+ Todo: allow indexing and searching on serialized info, like mongoid. (see: [group post](https://groups.google.com/d/msg/neo4jrb/KWxKBMbCc9E/E2XKIhzyvucJ)
25
+
26
+
27
+ ### Automatic object creation
28
+
29
+ Notices a passed-in hash to a relationship, and makes the right node. You can pass a block if it returns a model instance.
30
+
31
+ # user.rb
32
+ has_one(:location).to(Location)
33
+ accepts_hash_for :location do |attributes|
34
+ Location.new attributes
35
+ end
36
+
37
+ In fact, the above is done automatically with no block, so this is just the same effect:
38
+
39
+ # user.rb
40
+ has_one(:location).to(Location)
41
+ accepts_hash_for :location
42
+
43
+ ### Misc
44
+
45
+
46
+ TODO: niceties to try and bring the syntax as close as possible to mongoid;
47
+
48
+ - .limit(), .page(), and .sort(),
49
+ - allowing the :unique flag to be passed to indexes (like mongoid),
50
+ - making the difference between the Lucene query and neo4j traversal more evident, useful, or hidden
51
+ - looking for some syntactic sugar so that its not necessary to do a wildcard query returning a lucene search in order to run a sort.
52
+ - command to automatically add missing indexes
53
+ - whatever comes next
54
+
55
+
56
+
57
+ ## Contributing
58
+
59
+
60
+ Once you've made your great commits
61
+
62
+ 1. Fork
63
+ 1. Pull # > git clone git://whatever
64
+ 1. Push # > git push
65
+ 1. Pull request # github's GUI
66
+ 1. \# That's it!
67
+
68
+
69
+
70
+ ## Contributors
71
+
72
+ Peter Ehrlich [@ehrlicp](http://www.twitter.com/ehrlicp)
73
+ <br/>
74
+ (This rdoc written with Mou, a sweet markdown editor from [@chenluois](http://twitter.com/chenluois))
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "neo4j_helper"
18
+ gem.homepage = "http://github.com/pehrlich/neo4j_helper"
19
+ gem.license = "WTFPL"
20
+ gem.summary = %Q{Making neo4j gem mo' spiffy for your data-nomming needs}
21
+ gem.description = %Q{Attemting to minimize the syntactical learning curve from other ORMs}
22
+ gem.email = "peter.i.ehrlich@gmail.com"
23
+ gem.authors = ["Peter Ehrlich"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "neo4j_helper #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ require 'neo4j_helper/accepts_hash_for'
2
+ require 'neo4j_helper/serialize'
3
+ require 'neo4j_helper/misc'
@@ -0,0 +1,64 @@
1
+ module Neo4j
2
+ module Rails
3
+ class Model
4
+ class << self
5
+
6
+ # This allows anything to be thrown at a relationship and understood.
7
+ # usage:
8
+ #
9
+ # has_one(:location).to(Location)
10
+ # accepts_hash_for :location
11
+ #
12
+ # Will run Location.new with the passed in :location hash.
13
+ # You can also give it a block which returns a location node:
14
+ #
15
+ # accepts_hash_for :location do |location_attributes|
16
+ # Location.find_or_create_by(:name => location_attributes[:name])
17
+ # end
18
+ #
19
+ def accepts_hash_for(prop, *block)
20
+ # todo: handle persistence?
21
+ # for working with this method, see these neo4j examples:
22
+ # def _add_relationship(rel_type, node)
23
+ # def update_nested_attributes
24
+ # def accepts_nested_attributes_for
25
+
26
+ rel = self._decl_rels[prop.to_sym]
27
+ raise "No relationship declared with has_n or has_one with type #{prop}" unless rel
28
+
29
+ if rel.has_one?
30
+ setter = :"#{prop}="
31
+ original_setter = :"#{prop}_without_accepting_hash="
32
+
33
+ define_method :"#{prop}_with_accepting_hash=" do |attributes|
34
+
35
+ node = if attributes.is_a? rel.target_class
36
+ attributes
37
+ elsif attributes.present?
38
+ # not sure what would be to happen if a block were somehow to be given to the setter method
39
+ if block_given?
40
+ yield(attributes)
41
+ else
42
+ # todo: allow find_or_create
43
+ target_class.new attributes
44
+ end
45
+ else
46
+ nil
47
+ end
48
+
49
+ send(original_setter, node)
50
+ end
51
+
52
+ alias_method_chain setter, :accepting_hash
53
+ end
54
+
55
+ else
56
+ # todo: has_n
57
+ end
58
+
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+ module Neo4jHelpers
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method :properties, :attributes
7
+ end
8
+
9
+ module InstanceMethods
10
+
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ def find_by(options)
16
+ self.find(options)
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+
24
+ =begin
25
+ todo:
26
+
27
+ So far will mainly include niceties to try and bring the syntax as close as possible to mongoid;
28
+ - .limit(), .page(), and .sort(),
29
+ - allowing the :unique flag to be passed to indexes (like mongoid),
30
+ - making the difference between the Lucene query and neo4j traversal more evident, useful, or hidden
31
+ - looking for some syntactic sugar so that its not necessary to do a wildcard query returning a lucene search in order to run a sort.
32
+ - command to automatically add missing indexes
33
+ - figure out "title: long" vs :title => "long"
34
+
35
+ - way to obtain write lock without quitting and restarting server?
36
+
37
+ =end
@@ -0,0 +1,25 @@
1
+ module Neo4j
2
+ module TypeConverters
3
+ class SerializeConverter
4
+ # serializes to sting
5
+ class << self
6
+
7
+ def convert?(type)
8
+ type == :serialize
9
+ end
10
+
11
+ def to_java(value)
12
+ return nil unless value
13
+ JSON.generate(value).to_s
14
+ end
15
+
16
+ def to_ruby(value)
17
+ return nil unless value
18
+ JSON.parse(value.to_s)
19
+ end
20
+ end
21
+
22
+ end
23
+ converters = nil # reload converters
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "neo4j_helper"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Peter Ehrlich"]
12
+ s.date = "2012-01-25"
13
+ s.description = "Attemting to minimize the syntactical learning curve from other ORMs"
14
+ s.email = "peter.i.ehrlich@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/neo4j_helper.rb",
28
+ "lib/neo4j_helper/accepts_hash_for.rb",
29
+ "lib/neo4j_helper/misc.rb",
30
+ "lib/neo4j_helper/serialize.rb",
31
+ "neo4j_helper.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_neo4j_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/pehrlich/neo4j_helper"
36
+ s.licenses = ["WTFPL"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.13"
39
+ s.summary = "Making neo4j gem mo' spiffy for your data-nomming needs"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ else
48
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ end
55
+ end
56
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'neo4j_helper'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestNeo4jHelper < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neo4j_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Peter Ehrlich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70196155311840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70196155311840
25
+ - !ruby/object:Gem::Dependency
26
+ name: jeweler
27
+ requirement: &70196155310760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.4
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70196155310760
36
+ description: Attemting to minimize the syntactical learning curve from other ORMs
37
+ email: peter.i.ehrlich@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - LICENSE.txt
42
+ - README.md
43
+ files:
44
+ - .document
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/neo4j_helper.rb
52
+ - lib/neo4j_helper/accepts_hash_for.rb
53
+ - lib/neo4j_helper/misc.rb
54
+ - lib/neo4j_helper/serialize.rb
55
+ - neo4j_helper.gemspec
56
+ - test/helper.rb
57
+ - test/test_neo4j_helper.rb
58
+ homepage: http://github.com/pehrlich/neo4j_helper
59
+ licenses:
60
+ - WTFPL
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ segments:
72
+ - 0
73
+ hash: 3732617207430592
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.13
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Making neo4j gem mo' spiffy for your data-nomming needs
86
+ test_files: []