smooth_operator 1.10.18 → 1.10.19
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 +8 -8
- data/lib/smooth_operator/delegation.rb +1 -1
- data/lib/smooth_operator/model_schema.rb +4 -4
- data/lib/smooth_operator/open_struct.rb +8 -0
- data/lib/smooth_operator/version.rb +1 -1
- data/lib/smooth_operator.rb +2 -0
- data/spec/smooth_operator/delegation_spec.rb +67 -18
- data/spec/smooth_operator/finder_methods_spec.rb +1 -1
- data/spec/support/models/user.rb +0 -1
- data/spec/support/models/user_with_address_and_posts.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmMyMDMzNzhjMDJjYjZlMWQ1OWJiZWJiMjU0ODdmNDllMjhiMjYyNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWU3M2FhMDUwNjQxYTQzYmVkYmQ0ZTFjZDI3ODY4YjMxYzUyODQ3MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTljZGY2ZTAxYmY0MGQxMWE2YTE5MzNkY2ZkNTA1NzRhOGE3ZmE3NGMwNjA3
|
10
|
+
MDkzNGQ5NmVkMzIxMjFkNmM3ODgyNTYyYWEyMWYxNDY5MDU2OTBhNDAyNjQz
|
11
|
+
MzY5MjMzYWFkZjg0MDU1MDEyYTMzNmVhNWYxMzhkNzU0NTlhNGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
data/lib/smooth_operator.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
73
|
-
|
97
|
+
context "when .strict_behaviour is false" do
|
98
|
+
subject { UserWithAddressAndPosts::SoftBehaviour.new(attributes_for(:user_with_address_and_posts)) }
|
74
99
|
|
75
|
-
|
76
|
-
|
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
|
-
|
80
|
-
|
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
|
-
|
84
|
-
|
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
|
|
data/spec/support/models/user.rb
CHANGED
@@ -2,7 +2,7 @@ module UserWithAddressAndPosts
|
|
2
2
|
|
3
3
|
class Father < User::Base
|
4
4
|
|
5
|
-
self.
|
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
|
27
|
+
class SoftBehaviour < Son
|
28
|
+
|
29
|
+
self.strict_behaviour = false
|
30
30
|
|
31
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
class WithPatch < Son
|
32
34
|
|
33
35
|
self.update_http_verb = :patch
|
34
36
|
|