architect4r 0.3.4 → 0.3.4.1
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/Gemfile.lock +1 -1
- data/ReleaseNotes.md +4 -0
- data/lib/architect4r/core/node_methods.rb +4 -0
- data/lib/architect4r/model/relationship.rb +39 -0
- data/lib/architect4r/version.rb +1 -1
- data/spec/model/relationship_spec.rb +32 -0
- data/spec/spec_helper.rb +1 -1
- metadata +4 -3
data/Gemfile.lock
CHANGED
data/ReleaseNotes.md
CHANGED
@@ -100,6 +100,45 @@ module Architect4r
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
|
104
|
+
def source
|
105
|
+
@source ||= begin
|
106
|
+
if raw_data && raw_data['start']
|
107
|
+
start_node_id = connection.node_id(raw_data['start'])
|
108
|
+
if result = connection.cypher_query("start n=node(#{start_node_id}) return n")
|
109
|
+
result.first['n']
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def destination
|
116
|
+
@destination ||= begin
|
117
|
+
if raw_data && raw_data['end']
|
118
|
+
start_node_id = connection.node_id(raw_data['end'])
|
119
|
+
if result = connection.cypher_query("start n=node(#{start_node_id}) return n")
|
120
|
+
result.first['n']
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
#
|
128
|
+
# Class methods
|
129
|
+
#
|
130
|
+
|
131
|
+
|
132
|
+
def self.find(id)
|
133
|
+
data = connection.execute_cypher("start r=relationship(#{id}) return r")
|
134
|
+
data &&= data['data'] && data['data'].flatten.first
|
135
|
+
self.build_from_database(data)
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.find!(id)
|
139
|
+
self.find(id) || raise(Architect4r::RecordNotFound.new("Could not find the #{self.name} with id #{id}!"))
|
140
|
+
end
|
141
|
+
|
103
142
|
end
|
104
143
|
end
|
105
144
|
end
|
data/lib/architect4r/version.rb
CHANGED
@@ -60,4 +60,36 @@ describe Architect4r::Model::Relationship do
|
|
60
60
|
|
61
61
|
end
|
62
62
|
|
63
|
+
describe "Retrieve records from the store" do
|
64
|
+
|
65
|
+
it "should allow fetching a record by its id" do
|
66
|
+
CrewMembership.should respond_to(:find)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should instantiate a relationship model" do
|
70
|
+
ms = CrewMembership.create(ship, person, { :rank => 'Captain' })
|
71
|
+
CrewMembership.find(ms.id).should be_a(CrewMembership)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Should populate source and destination after retrieval from storage" do
|
77
|
+
|
78
|
+
let(:membership) { CrewMembership.create(ship, person, { :rank => 'Captain' }) }
|
79
|
+
|
80
|
+
subject { CrewMembership.find(membership.id) }
|
81
|
+
|
82
|
+
it { should respond_to(:source) }
|
83
|
+
it { should respond_to(:destination) }
|
84
|
+
|
85
|
+
it "should populate the source after retrieval" do
|
86
|
+
subject.source.id.should == ship.id
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should populate the destination after retrieval" do
|
90
|
+
subject.destination.id.should == person.id
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
63
95
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: architect4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 69
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
9
|
- 4
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 0.3.4.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Maximilian Schulz
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-
|
19
|
+
date: 2011-11-18 00:00:00 Z
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activemodel
|