neo4apis 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +8 -18
- data/lib/neo4apis/base.rb +34 -17
- data/lib/neo4apis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 435f18b35183016cf989780b44ca0e551f53c4b2
|
4
|
+
data.tar.gz: 127f94b29ba58b55709691b6c3823c384daf0dbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea2f6f6f40d3a224fe39c57c6ca25b6a248b51aac3f3e71c2e759bc1952f97d65ae79228430e73aaabd78a6d8c818984ad83fcde4ed6ab097e3b3d9e0395586c
|
7
|
+
data.tar.gz: 240362413f2b4bfb21efb5ee9b73e3a0423dd1be6b78d5a5a7632f167af382f1e09af167c9462ada6f451ee389410cd053ae0851fbfa0ab4c0eb664ac993f8fa
|
data/README.md
CHANGED
@@ -8,18 +8,8 @@ In the below example we assume that a variable `awesome_client` is passed in whi
|
|
8
8
|
|
9
9
|
module Neo4Apis
|
10
10
|
class AwesomeSite < Base
|
11
|
-
|
12
|
-
|
13
|
-
def initialize(neo4j_client, options = {})
|
14
|
-
@client = options[:awesome_client]
|
15
|
-
|
16
|
-
options[:uuids] = (options[:uuids] || {}).merge({
|
17
|
-
User: :id,
|
18
|
-
Widget: :uuid
|
19
|
-
})
|
20
|
-
|
21
|
-
super(neo4j_client, options)
|
22
|
-
end
|
11
|
+
uuid :User, :id
|
12
|
+
uuid :Widget, :uuid
|
23
13
|
|
24
14
|
def import_widget_search(*args)
|
25
15
|
@client.widget_search(*args).each do |widget|
|
@@ -27,9 +17,7 @@ In the below example we assume that a variable `awesome_client` is passed in whi
|
|
27
17
|
end
|
28
18
|
end
|
29
19
|
|
30
|
-
|
31
|
-
|
32
|
-
def add_widget(widget)
|
20
|
+
importer :Widget do |widget|
|
33
21
|
user_node = add_user(widget.owner)
|
34
22
|
|
35
23
|
# add_node comes from From Neo4Apis::Base
|
@@ -44,7 +32,7 @@ In the below example we assume that a variable `awesome_client` is passed in whi
|
|
44
32
|
node
|
45
33
|
end
|
46
34
|
|
47
|
-
|
35
|
+
importer :User do |user|
|
48
36
|
add_node :User, {
|
49
37
|
id: user.id,
|
50
38
|
username: user.username,
|
@@ -63,10 +51,12 @@ Then somebody else could use your gem in the following manner:
|
|
63
51
|
neo4j_session = Neo4j::Session.open # From the neo4j-core gem
|
64
52
|
awesome_client = Awesome.open # From a theoretical API wrapping gem
|
65
53
|
|
66
|
-
neo4apis_awesome = Neo4Apis::AwesomeSite.new(neo4j_session
|
54
|
+
neo4apis_awesome = Neo4Apis::AwesomeSite.new(neo4j_session)
|
67
55
|
|
68
56
|
neo4apis_awesome.batch do
|
69
|
-
|
57
|
+
awesome_client.widget_search('cool').each do |widget|
|
58
|
+
import :Widget, widget # import is provided by neo4apis
|
59
|
+
end
|
70
60
|
end
|
71
61
|
|
72
62
|
```
|
data/lib/neo4apis/base.rb
CHANGED
@@ -3,25 +3,14 @@ module Neo4Apis
|
|
3
3
|
DEFAULT_FLUSH_SIZE = 500
|
4
4
|
|
5
5
|
NODE_PROXIES = {}
|
6
|
+
IMPORTERS = {}
|
7
|
+
|
8
|
+
attr_reader :options
|
6
9
|
|
7
10
|
def initialize(neo4j_session, options = {})
|
8
11
|
@buffer = QueryBuffer.new(neo4j_session)
|
12
|
+
@options = options
|
9
13
|
@flush_size = DEFAULT_FLUSH_SIZE
|
10
|
-
(options[:uuids] || {}).each do |label, uuid_field|
|
11
|
-
NODE_PROXIES[label] = Struct.new(:label, :props) do
|
12
|
-
const_set(:UUID_FIELD, uuid_field)
|
13
|
-
|
14
|
-
def uuid_value
|
15
|
-
raise ArgumentError, "props does not have UUID field `#{uuid_field}` for #{self.inspect}" if not props.has_key?(uuid_field)
|
16
|
-
|
17
|
-
props[uuid_field]
|
18
|
-
end
|
19
|
-
|
20
|
-
def uuid_field
|
21
|
-
self.class::UUID_FIELD
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
14
|
end
|
26
15
|
|
27
16
|
def add_node(label, props = {})
|
@@ -44,16 +33,44 @@ module Neo4Apis
|
|
44
33
|
@buffer << create_relationship_query(type, source, target, props)
|
45
34
|
end
|
46
35
|
|
47
|
-
def batch
|
36
|
+
def batch(&block)
|
48
37
|
@in_batch = true
|
49
38
|
|
50
|
-
|
39
|
+
instance_eval &block
|
51
40
|
|
52
41
|
@buffer.flush
|
53
42
|
ensure
|
54
43
|
@in_batch = false
|
55
44
|
end
|
56
45
|
|
46
|
+
def import(label, object)
|
47
|
+
self.instance_exec object, &IMPORTERS[label.to_sym]
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.importer(label, &block)
|
51
|
+
IMPORTERS[label.to_sym] = block
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.uuid(label, uuid_field)
|
55
|
+
NODE_PROXIES[label.to_sym] = node_proxy_from_uuid(label.to_sym, uuid_field.to_sym)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.node_proxy_from_uuid(label, uuid_field)
|
59
|
+
Struct.new(:label, :props) do
|
60
|
+
const_set(:UUID_FIELD, uuid_field)
|
61
|
+
|
62
|
+
def uuid_value
|
63
|
+
raise ArgumentError, "props does not have UUID field `#{uuid_field}` for #{self.inspect}" if not props.has_key?(uuid_field)
|
64
|
+
|
65
|
+
props[uuid_field]
|
66
|
+
end
|
67
|
+
|
68
|
+
def uuid_field
|
69
|
+
self.class::UUID_FIELD
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
57
74
|
private
|
58
75
|
|
59
76
|
def create_node_query(node_proxy)
|
data/lib/neo4apis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4apis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|