active_node 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_node.rb +1 -0
- data/lib/active_node/base.rb +1 -0
- data/lib/active_node/persistence.rb +24 -9
- data/lib/active_node/typecasting.rb +14 -0
- data/lib/active_node/typecasting/time_typecaster.rb +12 -0
- data/lib/active_node/version.rb +1 -1
- data/spec/functional/graph_spec.rb +8 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda1ec188ea5746ae414a8192aafe9cfbfbc0d19
|
4
|
+
data.tar.gz: 5c6e6984bfc33b7bc102fa1b88005cc36d4b6f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dfec1170324f4d06ef8e8eb7e09fb0224ce5a7e72683298bdbe625b7d574f5e6d6f8a649b43cabd39f5be947584a215b3c123d63426ffbe57cf9bb0ed867466
|
7
|
+
data.tar.gz: e29c1ca9dfa3113f45cb129dc6e89aa9b03336b0ff161e1ec1a19193debaee1de48a5e39c6447a938933b8455b64d3b466fd1bc22144f0854159426c97fac1ab
|
data/lib/active_node.rb
CHANGED
data/lib/active_node/base.rb
CHANGED
@@ -15,8 +15,8 @@ module ActiveNode
|
|
15
15
|
delegate :all, :first, :where, :limit, :includes, :delete_all, :build, :find, :offset, :count, :order, to: :graph
|
16
16
|
|
17
17
|
def timestamps
|
18
|
-
attribute :created_at, type:
|
19
|
-
attribute :updated_at, type:
|
18
|
+
attribute :created_at, type: Time
|
19
|
+
attribute :updated_at, type: Time
|
20
20
|
end
|
21
21
|
|
22
22
|
def find_by_cypher query, params={}, klass=nil
|
@@ -86,10 +86,6 @@ module ActiveNode
|
|
86
86
|
id.to_s if persisted?
|
87
87
|
end
|
88
88
|
|
89
|
-
def to_key
|
90
|
-
id
|
91
|
-
end
|
92
|
-
|
93
89
|
def persisted?
|
94
90
|
id.present? && !destroyed?
|
95
91
|
end
|
@@ -137,11 +133,15 @@ module ActiveNode
|
|
137
133
|
end
|
138
134
|
|
139
135
|
def update_attributes attributes
|
140
|
-
attributes.each { |key, value|
|
136
|
+
attributes.each { |key, value| respond_to_non_id_writer?(key) ? write_attr(key, value) : self[key]=value }
|
141
137
|
save
|
142
138
|
end
|
143
139
|
|
144
140
|
private
|
141
|
+
def respond_to_non_id_writer? attr
|
142
|
+
respond_to_writer?(attr) && attr.to_s != 'id'
|
143
|
+
end
|
144
|
+
|
145
145
|
def split_hash hash, method, split_by
|
146
146
|
hash.try(method) { |k, _| send split_by, k }
|
147
147
|
end
|
@@ -182,7 +182,7 @@ module ActiveNode
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def write
|
185
|
-
now = Time.now
|
185
|
+
now = Time.now
|
186
186
|
try :updated_at=, now
|
187
187
|
if persisted?
|
188
188
|
write_properties
|
@@ -202,7 +202,22 @@ module ActiveNode
|
|
202
202
|
end
|
203
203
|
|
204
204
|
def all_attributes
|
205
|
-
attributes.except('id').merge(@hash)
|
205
|
+
to_neo! attributes.except('id').merge(@hash)
|
206
|
+
end
|
207
|
+
|
208
|
+
def to_neo! attrs
|
209
|
+
attrs.each { |k, v| attrs[k] = to_neo v }
|
210
|
+
end
|
211
|
+
|
212
|
+
def to_neo value
|
213
|
+
case value
|
214
|
+
when Time, DateTime
|
215
|
+
value.utc.iso8601(6)
|
216
|
+
when Date
|
217
|
+
value.to_s
|
218
|
+
else
|
219
|
+
value
|
220
|
+
end
|
206
221
|
end
|
207
222
|
end
|
208
223
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_node/typecasting/time_typecaster"
|
2
|
+
|
3
|
+
module ActiveNode
|
4
|
+
module Typecasting
|
5
|
+
# @private
|
6
|
+
EXTENDED_TYPECASTER_MAP = {
|
7
|
+
Time => TimeTypecaster
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def typecaster_for(type)
|
11
|
+
EXTENDED_TYPECASTER_MAP[type].try(:new) or super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/active_node/version.rb
CHANGED
@@ -41,7 +41,14 @@ describe ActiveNode::Graph do
|
|
41
41
|
|
42
42
|
describe '#detect' do
|
43
43
|
it 'should return nil' do
|
44
|
-
Person.all.detect{|p| true}.should be_nil
|
44
|
+
Person.all.detect { |p| true }.should be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#includes' do
|
49
|
+
it 'should not throw an error' do
|
50
|
+
p = Person.create! father: Person.create!
|
51
|
+
Person.where(id: p.id).includes(:father).first.should == p
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -175,6 +175,8 @@ files:
|
|
175
175
|
- lib/active_node/persistence.rb
|
176
176
|
- lib/active_node/reflection.rb
|
177
177
|
- lib/active_node/relationship.rb
|
178
|
+
- lib/active_node/typecasting.rb
|
179
|
+
- lib/active_node/typecasting/time_typecaster.rb
|
178
180
|
- lib/active_node/validations.rb
|
179
181
|
- lib/active_node/validations/uniqueness.rb
|
180
182
|
- lib/active_node/version.rb
|