smooth_operator 1.10.18 → 1.10.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQ3ZWNiNWFhZGZiNWYyOGJiZmQ5Y2VlNjEyNTc4MzRlYzNiMzE2MA==
4
+ NmMyMDMzNzhjMDJjYjZlMWQ1OWJiZWJiMjU0ODdmNDllMjhiMjYyNg==
5
5
  data.tar.gz: !binary |-
6
- MWVlNzhiNWZhNjFlYWJlY2Q3YzY3MDM2NTZmYmJkZGMwMGM3YzIyZQ==
6
+ ZWU3M2FhMDUwNjQxYTQzYmVkYmQ0ZTFjZDI3ODY4YjMxYzUyODQ3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OThjMTlhZTA3MmY1ZDNjZjZmZTRiNmZiMDZlZDgxOTVhMGM0YzFlNTBiZTMw
10
- MzBmNzZhOWI4NDgyYTBlZWFkNzUxNDUyNjA4MjQ4NjE2MzU0OTkwN2ViN2Uy
11
- MDIwMDM4YzRiNmJiOTEyMjgxMDE5MTRjODJkMmRjN2I3NWMxYmM=
9
+ YTljZGY2ZTAxYmY0MGQxMWE2YTE5MzNkY2ZkNTA1NzRhOGE3ZmE3NGMwNjA3
10
+ MDkzNGQ5NmVkMzIxMjFkNmM3ODgyNTYyYWEyMWYxNDY5MDU2OTBhNDAyNjQz
11
+ MzY5MjMzYWFkZjg0MDU1MDEyYTMzNmVhNWYxMzhkNzU0NTlhNGY=
12
12
  data.tar.gz: !binary |-
13
- NmFiNjRhYzkxNWQ4ZTFkOTM0OGEyMTUzZjE3ZjE2ZjNmMTdjNzE5OGRjYjBi
14
- MDM5NGZmYTIxMGUyOGFkMGIyYWRhZTcyNzY0MWNmZDhjZWU4NjY5ZTUzMTlh
15
- OGNiNTRjZDQyZGZmZWI3YWQxZTgzZTZlY2M2MDM5YWY2MjgxZGI=
13
+ YzgxNWU5ZWRlYTA5ZjdhNDBkZWNmOWMyODlhYmJiNWIxM2YyMTBlYjMwZDky
14
+ YjBhMjE1OGUzMTQwMzNkNjEyZTk1Mzg5Mzk4MmQyY2Y2MzhlZTg1MTFlZTU5
15
+ MTEwNzJkYTUyOGM1ZGM1ZDc0Y2VjYmYyOGMzOWEyNmQ1NTc3NGU=
@@ -17,7 +17,7 @@ module SmoothOperator
17
17
  when :setter
18
18
  return push_to_internal_data(method_name, args.first)
19
19
  else
20
- return get_internal_data(method_name) if respond_to?(method_name)
20
+ return get_internal_data(method_name) if !self.class.strict_behaviour || respond_to?(method_name)
21
21
  end
22
22
 
23
23
  result.nil? ? super : result
@@ -25,13 +25,13 @@ module SmoothOperator
25
25
 
26
26
  module ClassMethods
27
27
 
28
- def resources_name
29
- @resources_name ||= self.resource_name.pluralize
28
+ def resources_name(default_bypass = nil)
29
+ @resources_name ||= (Helpers.super_method(self, :resources_name, true) || (default_bypass ? nil : self.resource_name.pluralize))
30
30
  end
31
31
  attr_writer :resources_name
32
32
 
33
- def resource_name
34
- @resource_name ||= self.model_name.to_s.underscore.pluralize
33
+ def resource_name(default_bypass = nil)
34
+ @resource_name ||= (Helpers.super_method(self, :resource_name, true) || (default_bypass ? nil : self.model_name.to_s.underscore.pluralize))
35
35
  end
36
36
  attr_writer :resource_name
37
37
 
@@ -15,6 +15,14 @@ module SmoothOperator
15
15
  include Serialization
16
16
  include AttributeAssignment
17
17
 
18
+ def self.strict_behaviour=(value)
19
+ @strict_behaviour = value
20
+ end
21
+
22
+ def self.strict_behaviour
23
+ Helpers.get_instance_variable(self, :strict_behaviour, false)
24
+ end
25
+
18
26
  end
19
27
 
20
28
  class Dirty < Base
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.18"
2
+ VERSION = "1.10.19"
3
3
  end
@@ -18,6 +18,8 @@ module SmoothOperator
18
18
 
19
19
  attr_reader :last_remote_call
20
20
 
21
+ self.strict_behaviour = true
22
+
21
23
  end
22
24
 
23
25
  end
@@ -54,34 +54,83 @@ describe SmoothOperator::Delegation do
54
54
  end
55
55
  end
56
56
 
57
+ context "when .strict_behaviour is true" do
58
+ subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
57
59
 
58
- subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
60
+ context "when calling a method that doesn't match the initialized attributes but matches the schema" do
61
+ it 'it should return nil' do
62
+ expect(subject.manager).to eq(nil)
63
+ end
59
64
 
60
- context "when calling a method that doesn't match the initialized attributes but matches the schema" do
61
- it 'it should return nil' do
62
- expect(subject.manager).to eq(nil)
65
+ it "#respond_to? must return true" do
66
+ expect(subject.respond_to?(:manager)).to eq(true)
67
+ end
63
68
  end
64
- end
65
69
 
66
- context "when calling a method that doesn't match either the schema nor the initialized attributes" do
67
- it 'it should raise NoMethodError' do
68
- expect { subject.unknown_method }.to raise_error NoMethodError
70
+ context "when calling a method that doesn't match either the schema nor the initialized attributes" do
71
+ it 'it should raise NoMethodError' do
72
+ expect { subject.unknown_method }.to raise_error NoMethodError
73
+ end
74
+
75
+ it "#respond_to? must return false" do
76
+ expect(subject.respond_to?(:unknown_method)).to eq(false)
77
+ end
78
+ end
79
+
80
+ context "when setting a new attribute not declared on schema" do
81
+ before { subject.unknown_attribute = 'unknown_value' }
82
+
83
+ it "#known_attributes must reflect that new attribute" do
84
+ expect(subject.known_attributes.to_a).to include('unknown_attribute')
85
+ end
86
+
87
+ it "#respond_to? must return true" do
88
+ expect(subject.respond_to?(:unknown_attribute)).to eq(true)
89
+ end
90
+
91
+ it "calling a method with the same name must return that attribute's value" do
92
+ expect(subject.unknown_attribute).to eq('unknown_value')
93
+ end
69
94
  end
70
95
  end
71
96
 
72
- context "when setting a new attribute not declared on schema" do
73
- before { subject.unknown_attribute = 'unknown_value' }
97
+ context "when .strict_behaviour is false" do
98
+ subject { UserWithAddressAndPosts::SoftBehaviour.new(attributes_for(:user_with_address_and_posts)) }
74
99
 
75
- it "#known_attributes must reflect that new attribute" do
76
- expect(subject.known_attributes.to_a).to include('unknown_attribute')
100
+ context "when calling a method that doesn't match the initialized attributes but matches the schema" do
101
+ it 'it should return nil' do
102
+ expect(subject.manager).to eq(nil)
103
+ end
104
+
105
+ it "#respond_to? must return true" do
106
+ expect(subject.respond_to?(:manager)).to eq(true)
107
+ end
77
108
  end
78
-
79
- it "#respond_to? must return true" do
80
- expect(subject.respond_to?(:unknown_attribute)).to eq(true)
109
+
110
+ context "when calling a method that doesn't match either the schema nor the initialized attributes" do
111
+ it 'it should return nil' do
112
+ expect(subject.unknown_method).to eq(nil)
113
+ end
114
+
115
+ it "#respond_to? must return false" do
116
+ expect(subject.respond_to?(:unknown_method)).to eq(false)
117
+ end
81
118
  end
82
-
83
- it "calling a method with the same name must return that attribute's value" do
84
- expect(subject.unknown_attribute).to eq('unknown_value')
119
+
120
+ context "when setting a new attribute not declared on schema" do
121
+ before { subject.unknown_attribute = 'unknown_value' }
122
+
123
+ it "#known_attributes must reflect that new attribute" do
124
+ expect(subject.known_attributes.to_a).to include('unknown_attribute')
125
+ end
126
+
127
+ it "#respond_to? must return true" do
128
+ expect(subject.respond_to?(:unknown_attribute)).to eq(true)
129
+ end
130
+
131
+ it "calling a method with the same name must return that attribute's value" do
132
+ expect(subject.unknown_attribute).to eq('unknown_value')
133
+ end
85
134
  end
86
135
  end
87
136
 
@@ -54,7 +54,7 @@ describe SmoothOperator::FinderMethods do
54
54
  end
55
55
 
56
56
  it "user should NOT contain meta_data" do
57
- expect{ user.status }.to raise_error NoMethodError
57
+ expect { user.status }.to raise_error NoMethodError
58
58
  end
59
59
  end
60
60
 
@@ -36,7 +36,6 @@ module User
36
36
 
37
37
  class TimeoutConnection < Base
38
38
  self.timeout = 1
39
- self.resource_name = 'user'
40
39
  end
41
40
 
42
41
  end
@@ -2,7 +2,7 @@ module UserWithAddressAndPosts
2
2
 
3
3
  class Father < User::Base
4
4
 
5
- self.resources_name = 'users'
5
+ self.resource_name = 'user'
6
6
 
7
7
  schema(
8
8
  posts: Post,
@@ -13,8 +13,6 @@ module UserWithAddressAndPosts
13
13
 
14
14
  class Son < Father
15
15
 
16
- self.resources_name = 'users'
17
-
18
16
  schema(
19
17
  age: :int,
20
18
  dob: :date,
@@ -26,9 +24,13 @@ module UserWithAddressAndPosts
26
24
 
27
25
  end
28
26
 
29
- class WithPatch < Son
27
+ class SoftBehaviour < Son
28
+
29
+ self.strict_behaviour = false
30
30
 
31
- self.resources_name = 'users'
31
+ end
32
+
33
+ class WithPatch < Son
32
34
 
33
35
  self.update_http_verb = :patch
34
36
 
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.18
4
+ version: 1.10.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Gonçalves