couchpillow 0.4.10 → 0.4.11

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: a06d6bda2c5d092ce129525276179029fa6f93c0
4
- data.tar.gz: 45a5414fc84538bcb84bf913d688e0b4fb3de476
3
+ metadata.gz: 696cfe25404a7a89de88ae8863e6388f3e20d48c
4
+ data.tar.gz: c0954f6feeb54438dc14ec6992aede890f83a54a
5
5
  SHA512:
6
- metadata.gz: 44d9569edb47479fd4ba5a149a2a0ebec1277d9572f2b6754c42361fff134c0d6735935a1037f683a4575eda65777af9920a87719c8d4b30bd91096c0469f9dc
7
- data.tar.gz: 1c7b4713f099a6212ec7db4385cdada55082331c9581f0f9c7c65e0ffd8960d676e2b6d2699ef8985f31b73b6a291e92f83c55900cb2fcbb45cc1d2ca411f5de
6
+ metadata.gz: 9e977460fa8a14e8af98bea41502312c3b9630780f796747bb105c4cc08e80ce4fd5fedd73c2380b35661af4e6daefaea3bebf2bdb680184ddbadf8d097987c8
7
+ data.tar.gz: 18ed07990ae09053e7930c47d754fc7cea8adb44fcacb657a1f11c7d24b434beccb475aeef64bb9873edd90a53e27ffcafac104afbc6ad8dfa61c763ca75bc44
@@ -162,8 +162,8 @@ module CouchPillow
162
162
  value = String(value)
163
163
  elsif @type == Array
164
164
  value = Array(value)
165
- elsif @type == Time && !value.is_a?(Time)
166
- value = Time.parse(value)
165
+ elsif (@type == Time || @type == Iso8601Time) && !value.is_a?(Time)
166
+ value = @type.parse(value)
167
167
  elsif @type == CouchPillow::Boolean
168
168
  value = value == 0 || value.to_s.downcase == "false" || !value ? false : true
169
169
  end
@@ -23,16 +23,16 @@ module CouchPillow
23
23
 
24
24
  attribute :_created_at do
25
25
  required
26
- type Time
26
+ type CouchPillow::Iso8601Time
27
27
  auto_convert
28
- default { Time.now.utc }
28
+ default { CouchPillow::Iso8601Time.now.utc }
29
29
  end
30
30
 
31
31
  attribute :_updated_at do
32
32
  required
33
- type Time
33
+ type CouchPillow::Iso8601Time
34
34
  auto_convert
35
- default { Time.now.utc }
35
+ default { CouchPillow::Iso8601Time.now.utc }
36
36
  end
37
37
 
38
38
 
@@ -50,7 +50,7 @@ module CouchPillow
50
50
 
51
51
  @id = self.class._is_type_prefixed? ? self.class._sanitize_id(id) : id
52
52
 
53
- time = Time.now.utc
53
+ time = CouchPillow::Iso8601Time.now.utc
54
54
  @data[:_created_at] ||= time
55
55
  @data[:_updated_at] ||= time
56
56
 
@@ -311,7 +311,7 @@ module CouchPillow
311
311
  # Timestamp this document
312
312
  #
313
313
  def _timestamp!
314
- @data[:_updated_at] = Time.now.utc
314
+ @data[:_updated_at] = CouchPillow::Iso8601Time.now.utc
315
315
  end
316
316
 
317
317
 
@@ -0,0 +1,11 @@
1
+ module CouchPillow
2
+
3
+ # Faux Boolean class used for type checking and conversion.
4
+ #
5
+ class Iso8601Time < Time
6
+ def to_s
7
+ iso8601
8
+ end
9
+ end
10
+
11
+ end
@@ -1,5 +1,5 @@
1
1
  module CouchPillow
2
2
  GEM_NAME = "couchpillow"
3
3
  NAME = "CouchPillow"
4
- VERSION = "0.4.10"
4
+ VERSION = "0.4.11"
5
5
  end
data/lib/couchpillow.rb CHANGED
@@ -16,6 +16,7 @@ module CouchPillow
16
16
  end
17
17
 
18
18
  require 'couchpillow/helper'
19
+ require 'couchpillow/iso8601'
19
20
 
20
21
  require 'couchpillow/directives/type'
21
22
  require 'couchpillow/directives/type_prefix'
@@ -38,6 +38,14 @@ class TestDocument < Minitest::Test
38
38
  end
39
39
 
40
40
 
41
+ def test_iso8601
42
+ d = Document.new({"_created_at" => "2008-06-21 13:30:00 UTC"}, "1")
43
+ d.save!
44
+ json = JSON.parse(d.to_json)
45
+ assert_equal "2008-06-21T13:30:00Z", json['_created_at']
46
+ end
47
+
48
+
41
49
  def test_default_type
42
50
  d = Document.new({}, "1")
43
51
  assert_equal "couchpillow", d.doc_type
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchpillow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: couchbase
@@ -89,6 +89,7 @@ files:
89
89
  - lib/couchpillow/document.rb
90
90
  - lib/couchpillow/errors.rb
91
91
  - lib/couchpillow/helper.rb
92
+ - lib/couchpillow/iso8601.rb
92
93
  - lib/couchpillow/version.rb
93
94
  - test/helper.rb
94
95
  - test/test_attribute.rb