tiny_dyno 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/lib/tiny_dyno/adapter/attributes.rb +38 -25
- data/lib/tiny_dyno/errors/invalid_type_error.rb +26 -0
- data/lib/tiny_dyno/persistable.rb +3 -1
- data/lib/tiny_dyno/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70bbda18ddd44e600dff1229f0372a9c130a5f69
|
4
|
+
data.tar.gz: 8e8d541dcc26084314b0426ef4f8a1a8b3b33f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2ea804ada4339457b6b1e2c0a94c8bc90d1d3f15f51abed3edcb1d3d05c4054d17bc054a704b3308da70b5e6e255b8b5d446b6656a2623247bbc9a50bc547e
|
7
|
+
data.tar.gz: 960bc0007d4e60b4ae4ab6c95cf07c99ad1b08492b3f263a277254004441cec8f57f8cb7aa0307704e82806f112c7ef9f5b0a31a2f78d94b335f9b28083e52e7
|
data/CHANGES.md
CHANGED
@@ -43,18 +43,7 @@ module TinyDyno
|
|
43
43
|
end
|
44
44
|
when 'String' then { s: obj }
|
45
45
|
when 'Symbol' then { s: obj.to_s }
|
46
|
-
when 'Numeric', 'Fixnum', 'Float', 'Integer'
|
47
|
-
if obj.to_i != 0 and obj != '0'
|
48
|
-
{ n: obj.to_s }
|
49
|
-
elsif obj.to_i === 0 and obj == '0'
|
50
|
-
{ n: obj.to_s }
|
51
|
-
elsif obj.is_a?(Integer)
|
52
|
-
{ n: obj.to_s }
|
53
|
-
elsif obj.nil?
|
54
|
-
{ null: true }
|
55
|
-
else
|
56
|
-
raise TinyDyno::Errors::InvalidValueType.new(klass: self.class, name: type, value: obj)
|
57
|
-
end
|
46
|
+
when 'Numeric', 'Fixnum', 'Float', 'Integer', 'BigDecimal' then numeric_format(type.to_s,obj)
|
58
47
|
when 'StringIO', 'IO' then { b: obj }
|
59
48
|
when 'Set' then format_set(obj)
|
60
49
|
when 'TrueClass', 'FalseClass', 'TinyDyno::Boolean'
|
@@ -62,15 +51,42 @@ module TinyDyno
|
|
62
51
|
raise TinyDyno::Errors::InvalidValueType.new(klass: self.class, name: type, value: obj) unless [true,false,nil].include?(obj)
|
63
52
|
{ bool: obj }
|
64
53
|
when 'NilClass' then { null: true }
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
54
|
+
else
|
55
|
+
msg = "unsupported type, expected Hash, Array, Set, String, Numeric, "
|
56
|
+
msg << "IO, true, false, or nil, got #{obj.class.name}"
|
57
|
+
raise ArgumentError, msg
|
69
58
|
end
|
70
|
-
end
|
59
|
+
end #format
|
71
60
|
|
72
61
|
private
|
73
62
|
|
63
|
+
def numeric_format(type,obj)
|
64
|
+
case type
|
65
|
+
when 'Fixnum', 'Integer', 'Numeric'
|
66
|
+
if obj.class == BigDecimal
|
67
|
+
raise TinyDyno::Errors::NotTransparentlyCoercible.new(klass: self.class, name: type, value: obj) unless obj == BigDecimal.new(obj.to_s)
|
68
|
+
{ n: obj.to_s }
|
69
|
+
elsif obj.class == String
|
70
|
+
raise TinyDyno::Errors::NotTransparentlyCoercible.new(klass: self.class, name: type, value: obj) unless obj.to_i.to_s == obj
|
71
|
+
{ n: obj }
|
72
|
+
else
|
73
|
+
raise TinyDyno::Errors::NotTransparentlyCoercible.new(klass: self.class, name: type, value: obj) unless obj.to_i == obj.to_s.to_i
|
74
|
+
{ n: obj.to_s }
|
75
|
+
end
|
76
|
+
when 'Float'
|
77
|
+
raise TinyDyno::Errors::InvalidValueType.new(klass: self.class, name: type, value: obj) unless obj.is_a?(Float)
|
78
|
+
raise TinyDyno::Errors::NotTransparentlyCoercible.new(klass: self.class, name: type, value: obj) unless obj == obj.to_s.to_f
|
79
|
+
{ n: obj.to_s }
|
80
|
+
when 'BigDecimal'
|
81
|
+
raise TinyDyno::Errors::InvalidValueType.new(klass: self.class, name: type, value: obj) unless obj.is_a?(BigDecimal)
|
82
|
+
raise TinyDyno::Errors::NotTransparentlyCoercible.new(klass: self.class, name: type, value: obj) unless obj == BigDecimal.new(obj.to_s)
|
83
|
+
{ n: obj.to_s}
|
84
|
+
else
|
85
|
+
msg = "unsupported type, expected Fixnum, Integer, Float, BigDecimal "
|
86
|
+
raise ArgumentError, msg
|
87
|
+
end
|
88
|
+
end #numeric_format
|
89
|
+
|
74
90
|
def format_set(set)
|
75
91
|
case set.first
|
76
92
|
when String, Symbol then { ss: set.map(&:to_s) }
|
@@ -80,9 +96,9 @@ module TinyDyno
|
|
80
96
|
msg = "set types only support String, Numeric, or IO objects"
|
81
97
|
raise ArgumentError, msg
|
82
98
|
end
|
83
|
-
end
|
99
|
+
end #format_set
|
84
100
|
|
85
|
-
end
|
101
|
+
end #AttributeValue
|
86
102
|
|
87
103
|
class Unmarshaler
|
88
104
|
|
@@ -147,12 +163,9 @@ module TinyDyno
|
|
147
163
|
raw_attribute = aws_attribute(field_type: field_type, value: value)
|
148
164
|
|
149
165
|
case field_type.to_s
|
150
|
-
when 'Fixnum', 'Integer'
|
151
|
-
|
152
|
-
when '
|
153
|
-
simple_value = doc_attribute(raw_attribute).to_f
|
154
|
-
when 'Numeric', 'String', 'Array', 'Hash', 'TinyDyno::Boolean' then
|
155
|
-
simple_value = doc_attribute(raw_attribute)
|
166
|
+
when 'Fixnum', 'Integer' then simple_value = doc_attribute(raw_attribute).to_i
|
167
|
+
when 'Float' then simple_value = doc_attribute(raw_attribute).to_f
|
168
|
+
when 'Numeric', 'String', 'Array', 'Hash', 'TinyDyno::Boolean' then simple_value = doc_attribute(raw_attribute)
|
156
169
|
else
|
157
170
|
raise ArgumentError, "unhandled type #{ field_type.inspect }"
|
158
171
|
end
|
@@ -24,3 +24,29 @@ module TinyDyno
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
# encoding: utf-8
|
28
|
+
module TinyDyno
|
29
|
+
module Errors
|
30
|
+
|
31
|
+
# This error is raised, when a query is performed with fields specified
|
32
|
+
# that are not HashKeys, which would result in a table scan
|
33
|
+
class NotTransparentlyCoercible < TinyDynoError
|
34
|
+
|
35
|
+
# Create the new error.
|
36
|
+
#
|
37
|
+
# @example Instantiate the error.
|
38
|
+
# InvalidSelector.new(Person, "gender")
|
39
|
+
#
|
40
|
+
# @param [ Class ] klass The model class.
|
41
|
+
# @param [ String, Symbol ] name The name of the attribute.
|
42
|
+
#
|
43
|
+
# @since 3.0.0
|
44
|
+
def initialize(klass:, name:, value:)
|
45
|
+
super(
|
46
|
+
compose_message("can_not_coerce_transparently", { klass: klass.name, name: name, value: value })
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -3,7 +3,9 @@ module TinyDyno
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def save(options = {})
|
6
|
-
|
6
|
+
unless options.has_key?(:validate) && options[:validate] == false
|
7
|
+
return false unless self.valid?
|
8
|
+
end
|
7
9
|
if new_record?
|
8
10
|
if request_put_item(options)
|
9
11
|
changes_applied
|
data/lib/tiny_dyno/version.rb
CHANGED