smooth_operator 1.10.19 → 1.10.20

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmMyMDMzNzhjMDJjYjZlMWQ1OWJiZWJiMjU0ODdmNDllMjhiMjYyNg==
4
+ NzJiNWZiMGU0ZTczYjY5OTM2ZTZlYTc4OGU2ZjdkMjQyYzA3NjljMA==
5
5
  data.tar.gz: !binary |-
6
- ZWU3M2FhMDUwNjQxYTQzYmVkYmQ0ZTFjZDI3ODY4YjMxYzUyODQ3MA==
6
+ NzM0MmE2ZDJhZDYwZGVmNDAwMTNkMjMzZTFhOWQxZTQzYTEyNjE4Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTljZGY2ZTAxYmY0MGQxMWE2YTE5MzNkY2ZkNTA1NzRhOGE3ZmE3NGMwNjA3
10
- MDkzNGQ5NmVkMzIxMjFkNmM3ODgyNTYyYWEyMWYxNDY5MDU2OTBhNDAyNjQz
11
- MzY5MjMzYWFkZjg0MDU1MDEyYTMzNmVhNWYxMzhkNzU0NTlhNGY=
9
+ MzhjODI0NTRkZWZiOTIzMDJiZWRhNjlkYTE1MmFjNmIzMDQxNTYwNjQ4MGVl
10
+ MTUxNGY4NTliNDc4YjA5MDA3MjAxMWM4ZWJkMzA3OGNmNDg4YjI0MjNmYjZm
11
+ MDJjNmFmNjU0YmVkYmUwMzE5YzUzM2IzOGQ5NjE5MDZmMDc0ZDQ=
12
12
  data.tar.gz: !binary |-
13
- YzgxNWU5ZWRlYTA5ZjdhNDBkZWNmOWMyODlhYmJiNWIxM2YyMTBlYjMwZDky
14
- YjBhMjE1OGUzMTQwMzNkNjEyZTk1Mzg5Mzk4MmQyY2Y2MzhlZTg1MTFlZTU5
15
- MTEwNzJkYTUyOGM1ZGM1ZDc0Y2VjYmYyOGMzOWEyNmQ1NTc3NGU=
13
+ OTZiNGE4NjhmYjE2Y2FiNjlmN2E5YjY0ZWVlMjE5ZjIzMzhkZWRiNTU4ZWMw
14
+ OTBkNzM1OGI5YTliMzE4MzE4NGY5MjA0ZTg2ZTUyMTE1MzdiZWI5ODBhY2Vk
15
+ NDk2MTIxMTkyNTIyN2E4Y2E3MjdiYzI1YzhlOTQ4NDBkN2Y0ZWE=
@@ -141,7 +141,7 @@ module SmoothOperator
141
141
 
142
142
  def update_internal_data(attribute_name, attribute_value)
143
143
  if self.class.dirty_attributes?
144
- internal_data[attribute_name].set_value(attribute_value, self.class.unknown_hash_class, self)
144
+ internal_data[attribute_name].set_value(attribute_value, self)
145
145
  else
146
146
  internal_data[attribute_name] = new_attribute_object(attribute_name, attribute_value).value
147
147
  end
@@ -150,7 +150,7 @@ module SmoothOperator
150
150
  def new_attribute_object(attribute_name, attribute_value)
151
151
  attribute_class = self.class.dirty_attributes? ? Attributes::Dirty : Attributes::Normal
152
152
 
153
- attribute_class.new(attribute_name, attribute_value, internal_structure[attribute_name], self.class.unknown_hash_class, self)
153
+ attribute_class.new(attribute_name, attribute_value, self)
154
154
  end
155
155
 
156
156
  end
@@ -5,10 +5,14 @@ module SmoothOperator
5
5
 
6
6
  protected ##################### PROTECTED ########################
7
7
 
8
- def cast_to_type(name, value, type, unknown_hash_class, parent_object)
8
+ def cast_to_type(name, value, parent_object)
9
+ known_by_schema, type, unknown_hash_class = parent_object.internal_structure.include?(name), parent_object.internal_structure[name], parent_object.class.unknown_hash_class
10
+
11
+ return Helpers.duplicate(value) if known_by_schema && type.nil?
12
+
9
13
  case value
10
14
  when Array
11
- value.map { |array_entry| self.class.new(name, array_entry, type, unknown_hash_class, parent_object).value }
15
+ value.map { |array_entry| self.class.new(name, array_entry, parent_object).value }
12
16
  when Hash
13
17
  type.nil? ? new_unknown_hash(value, unknown_hash_class, parent_object) : type.new(value, parent_object: parent_object)
14
18
  else
@@ -91,7 +95,7 @@ module SmoothOperator
91
95
  hash = {}
92
96
 
93
97
  attributes.each do |key, value|
94
- hash[key] = cast_to_type(key, value, nil, unknown_hash_class, parent_object)
98
+ hash[key] = cast_to_type(key, value, parent_object)
95
99
  end
96
100
 
97
101
  hash
@@ -3,16 +3,16 @@ module SmoothOperator
3
3
 
4
4
  class Dirty < Base
5
5
 
6
- attr_reader :original_name, :original_value, :first_value, :value, :type
6
+ attr_reader :original_name, :original_value, :first_value, :value
7
7
 
8
- def initialize(name, value, type, unknown_hash_class, parent_object)
9
- @original_name, @original_value, @type = name, value, type
8
+ def initialize(name, value, parent_object)
9
+ @original_name, @original_value = name, value
10
10
 
11
- @first_value = set_value(value, unknown_hash_class, parent_object)
11
+ @first_value = set_value(value, parent_object)
12
12
  end
13
13
 
14
- def set_value(new_value, unknown_hash_class, parent_object)
15
- @value = cast_to_type(original_name, new_value, type, unknown_hash_class, parent_object)
14
+ def set_value(new_value, parent_object)
15
+ @value = cast_to_type(original_name, new_value, parent_object)
16
16
  end
17
17
 
18
18
  def changed?
@@ -5,8 +5,8 @@ module SmoothOperator
5
5
 
6
6
  attr_reader :value
7
7
 
8
- def initialize(name, value, type, unknown_hash_class, parent_object)
9
- @value = cast_to_type(name, value, type, unknown_hash_class, parent_object)
8
+ def initialize(name, value, parent_object)
9
+ @value = cast_to_type(name, value, parent_object)
10
10
  end
11
11
 
12
12
  end
@@ -42,7 +42,7 @@ module SmoothOperator
42
42
  end
43
43
 
44
44
  def internal_structure
45
- Helpers.get_instance_variable(self, :internal_structure, {})
45
+ Helpers.get_instance_variable(self, :internal_structure, { "errors" => nil })
46
46
  end
47
47
 
48
48
  def known_attributes
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.19"
2
+ VERSION = "1.10.20"
3
3
  end
@@ -129,6 +129,34 @@ describe SmoothOperator::AttributeAssignment do
129
129
  context "when there is a known schema and the received hash has an attribute" do
130
130
  subject { UserWithAddressAndPosts::Son }
131
131
 
132
+ context "that is declared (in schema) as an nil" do
133
+
134
+ it "when the attributes's value is '1', should return '1'" do
135
+ expect(subject.new(complex_field: '1').complex_field).to eq('1')
136
+ end
137
+
138
+ it "when the attributes's value is ['1', '2'], should return ['1', '2']" do
139
+ expect(subject.new(complex_field: ['1', '2']).complex_field).to eq(['1', '2'])
140
+ end
141
+
142
+ it "when the attributes's value is 1, should be converted to 1" do
143
+ expect(subject.new(complex_field: 1).complex_field).to eq(1)
144
+ end
145
+
146
+ it "when the attributes's value is { first_name: ['1', '2'] }, should be converted to { first_name: ['1', '2'] }" do
147
+ expect(subject.new(complex_field: { first_name: ['1', '2'] }).complex_field).to eq({ first_name: ['1', '2'] })
148
+ end
149
+
150
+ it "when the attributes's value is -1, should be converted to -1" do
151
+ expect(subject.new(complex_field: -1).complex_field).to eq(-1)
152
+ end
153
+
154
+ it "when the attributes's value is 0.35, should be converted to 0.35" do
155
+ expect(subject.new(complex_field: 0.35).complex_field).to eq(0.35)
156
+ end
157
+
158
+ end
159
+
132
160
  context "that is declared (in schema) as an integer" do
133
161
 
134
162
  it "when the attributes's value is '1', should be converted to 1" do
@@ -19,6 +19,7 @@ module UserWithAddressAndPosts
19
19
  price: :float,
20
20
  manager: :bool,
21
21
  date: :datetime,
22
+ complex_field: nil,
22
23
  first_name: :string
23
24
  )
24
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smooth_operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.19
4
+ version: 1.10.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves