dynamo_record 0.0.9 → 0.0.10
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/lib/dynamo_record/document.rb +28 -1
- data/lib/dynamo_record/fields.rb +1 -1
- data/lib/dynamo_record/version.rb +1 -1
- data/spec/dynamo_record/fields_spec.rb +16 -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: 34854f8bcc2d2525ef5abc6394a326d7337c6735
|
4
|
+
data.tar.gz: f17c93d66790bec04b3fa1503c550a6afd97b20f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26cb8fe488e40a5d7d5ac8a41b0d100e5eb37c8af4e84ce2e8f338c737149ce6745ac6b3e54f43f8ab927312491c5195854c49e3dc7300916b9ffc5de091bb6c
|
7
|
+
data.tar.gz: 2588c0dd4b2fc17275b40cc4d33b4b182536006af8a81fd3dd30f3f67f1924c1c1e339e33768f88fa3bb308010805d7d1ed1c7b3723169b52a2081ccc982af49
|
@@ -30,9 +30,36 @@ module DynamoRecord
|
|
30
30
|
|
31
31
|
attrs.each do |key, value|
|
32
32
|
next if ignore_unknown_field && !respond_to?("#{key}=")
|
33
|
-
send("#{key}=", value)
|
33
|
+
send("#{key}=", undump_field(value, self.class.attributes[key.to_sym]))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def undump_field(value, options)
|
38
|
+
return nil if options.nil?
|
39
|
+
case options[:type]
|
40
|
+
when :integer
|
41
|
+
value.to_i
|
42
|
+
when :string
|
43
|
+
value.to_s
|
44
|
+
when :float
|
45
|
+
value.to_f
|
46
|
+
when :boolean
|
47
|
+
if value == "true" || value == true
|
48
|
+
true
|
49
|
+
elsif value == "false" || value == false
|
50
|
+
false
|
51
|
+
else
|
52
|
+
raise ArgumentError, "Boolean column neither true nor false"
|
53
|
+
end
|
54
|
+
when :datetime
|
55
|
+
if value.is_a?(Date) || value.is_a?(DateTime) || value.is_a?(Time)
|
56
|
+
value
|
57
|
+
else
|
58
|
+
DateTime.parse(value)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
raise ArgumentError, "Unknown type #{options[:type]}"
|
62
|
+
end
|
63
|
+
end
|
37
64
|
end
|
38
65
|
end
|
data/lib/dynamo_record/fields.rb
CHANGED
@@ -45,12 +45,27 @@ RSpec.describe DynamoRecord::Fields do
|
|
45
45
|
expect(person.name).to eq('A person')
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'coearce field to its data type' do
|
49
|
+
class Record
|
50
|
+
include DynamoRecord::Document
|
51
|
+
|
52
|
+
field :integer_field, :integer
|
53
|
+
field :float_field, :float
|
54
|
+
field :datetime_field, :datetime
|
55
|
+
field :boolean_field, :boolean
|
56
|
+
end
|
57
|
+
|
58
|
+
expect(Record.new(integer_field: '1').integer_field).to be_a(Fixnum)
|
59
|
+
expect(Record.new(float_field: '1').float_field).to be_a(Float)
|
60
|
+
expect(Record.new(datetime_field: '2014-12-25T04:08:25Z').datetime_field).to eq(DateTime.parse('2014-12-25T04:08:25Z'))
|
61
|
+
expect(Record.new(boolean_field: 'true').boolean_field).to be_truthy
|
62
|
+
end
|
63
|
+
|
48
64
|
describe 'predicate method' do
|
49
65
|
specify { expect(Person.new(activated: false).activated?).to be_falsy }
|
50
66
|
specify { expect(Person.new(activated: true).activated?).to be_truthy }
|
51
67
|
specify { expect(Person.new(activated: 'true').activated?).to be_truthy }
|
52
68
|
specify { expect(Person.new(activated: 'false').activated?).to be_falsy }
|
53
|
-
specify { expect(Person.new(activated: '').activated?).to be_truthy }
|
54
69
|
end
|
55
70
|
|
56
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamo_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nguyen Vu Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|