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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3c0d2fe8c063ac29c20b91a568919d9723d5b3e
4
- data.tar.gz: 11522535a767b8709c00420e83e9e2f2340f9a65
3
+ metadata.gz: cda1ec188ea5746ae414a8192aafe9cfbfbc0d19
4
+ data.tar.gz: 5c6e6984bfc33b7bc102fa1b88005cc36d4b6f62
5
5
  SHA512:
6
- metadata.gz: 81912f84e1e63e9fa220b0b67c07b15e58a30af7f8780e34cf72d68552e0a3347e7f6d6a2bcf59cd34d244f43afdd4b43ef2b2339b7fcefccdb1603bc77ebe33
7
- data.tar.gz: d38f3caad3486c0504d1aa51b40ec1433dd11a5b135ad0c3fca5c7c787b8219e06e3aa0585d345bbaa42bfe192d5d742f3e728c995cb4154e9b328ca0ff73eee
6
+ metadata.gz: 7dfec1170324f4d06ef8e8eb7e09fb0224ce5a7e72683298bdbe625b7d574f5e6d6f8a649b43cabd39f5be947584a215b3c123d63426ffbe57cf9bb0ed867466
7
+ data.tar.gz: e29c1ca9dfa3113f45cb129dc6e89aa9b03336b0ff161e1ec1a19193debaee1de48a5e39c6447a938933b8455b64d3b466fd1bc22144f0854159426c97fac1ab
data/lib/active_node.rb CHANGED
@@ -13,6 +13,7 @@ module ActiveNode
13
13
  autoload :Neo
14
14
  autoload :Relationship
15
15
  autoload :Graph
16
+ autoload :Typecasting
16
17
 
17
18
  autoload_under 'graph' do
18
19
  autoload :QueryMethods
@@ -7,6 +7,7 @@ module ActiveNode
7
7
  include ActiveAttr::Attributes
8
8
  include ActiveAttr::MassAssignment
9
9
  include ActiveAttr::TypecastedAttributes
10
+ include Typecasting
10
11
  include Dirty
11
12
  include Persistence
12
13
  include Validations
@@ -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: String
19
- attribute :updated_at, type: String
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| respond_to_writer?(attr) ? write_attr(key, value) : self[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.utc.iso8601(3)
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
@@ -0,0 +1,12 @@
1
+ require "active_support/core_ext/string/conversions"
2
+ require "active_support/time"
3
+
4
+ module ActiveNode
5
+ module Typecasting
6
+ class TimeTypecaster
7
+ def call(value)
8
+ value.to_time if value.respond_to? :to_time
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveNode
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
@@ -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.1
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-06 00:00:00.000000000 Z
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