tiny_dyno 0.1.22 → 0.1.23

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eeaba04a85bbf554f20bb8193bcc4a6701ff2ce
4
- data.tar.gz: 52468e676a52ae2a190df1d84355bd04f47c4011
3
+ metadata.gz: 70bbda18ddd44e600dff1229f0372a9c130a5f69
4
+ data.tar.gz: 8e8d541dcc26084314b0426ef4f8a1a8b3b33f19
5
5
  SHA512:
6
- metadata.gz: e6bd51cf221620d0efcd57de2989c8fd92bfe11f4609d3214cc8a5df29a2d6e1f5dfd10c180e602a3238df4c317d92d31dfd3354e19119e737aeb39de8f730cb
7
- data.tar.gz: c7e5d45da48fb83ac6344d57e4d24708321fa4a2a022fb100b155aa22821fed82669501d615dd17114b33bf389efdcb59096235ac91a7eea4a65b8e2adb005a8
6
+ metadata.gz: 0d2ea804ada4339457b6b1e2c0a94c8bc90d1d3f15f51abed3edcb1d3d05c4054d17bc054a704b3308da70b5e6e255b8b5d446b6656a2623247bbc9a50bc547e
7
+ data.tar.gz: 960bc0007d4e60b4ae4ab6c95cf07c99ad1b08492b3f263a277254004441cec8f57f8cb7aa0307704e82806f112c7ef9f5b0a31a2f78d94b335f9b28083e52e7
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ 0.1.23 (2015-09-09)
2
+ -------------------
3
+
4
+ * New - add support to toggle validation of records on save
5
+ * increase robustness of number type handling
6
+
7
+
1
8
  0.1.22 (2015-09-09)
2
9
  -------------------
3
10
 
@@ -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
- else
66
- msg = "unsupported type, expected Hash, Array, Set, String, Numeric, "
67
- msg << "IO, true, false, or nil, got #{obj.class.name}"
68
- raise ArgumentError, msg
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
- simple_value = doc_attribute(raw_attribute).to_i
152
- when 'Float'
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
- return false unless self.valid?
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
@@ -1,3 +1,3 @@
1
1
  module TinyDyno
2
- VERSION = '0.1.22'
2
+ VERSION = '0.1.23'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_dyno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gerschner