smooth_operator 1.20.9 → 1.20.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/smooth_operator/attribute_methods.rb +18 -4
- data/lib/smooth_operator/model_name.rb +50 -0
- data/lib/smooth_operator/open_struct.rb +3 -2
- data/lib/smooth_operator/schema.rb +33 -0
- data/lib/smooth_operator/version.rb +1 -1
- data/lib/smooth_operator.rb +2 -0
- data/spec/smooth_operator/{model_schema_spec.rb → model_name_spec.rb} +1 -1
- metadata +5 -4
- data/lib/smooth_operator/model_schema.rb +0 -81
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWVmZWM5OGI3M2I3NmM1MDA1NmQ4ODIzYTRlYzU1NjIzZDBiZDI1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjUxMTRlMDk0NDE1ZWI1ZWUwYTZhZWJhYWE3NzFmMmY0ZWEzYmQ2ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTFlYWU5MzJhMzZjZjk1MDdiOTlmNGYxNTkxMTJiOWJlYjg4MmZlMjVlYjU5
|
10
|
+
MDdhMGVjYjU2NDVjNWNkOTgzMjIwYzZhYzQ0ZGM2ZTQyYTY4ZDhmNmJmMTNm
|
11
|
+
MmFkNTBlMWM5MTBmZDU2Mjc2M2U1MWI0OTBhYmZmOTY2MWFkM2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWI0ZTIxYjY5NjJhYThhYWEyZmJmZTQ1ZmQyMDJhMDY0NTUxNDc3ODkyMGI3
|
14
|
+
MzZiY2I2YjMzNGFjMzZmMDdkYmM2YTY0NWE1Mjg2ODYyY2RiMDc4YjY0ODM3
|
15
|
+
YjY1MTM1OGQ1MWE0OTA5NzBjMjA3OWRjMmQ1YmM5OTQyOTkwOWY=
|
@@ -1,6 +1,24 @@
|
|
1
1
|
module SmoothOperator
|
2
2
|
module AttributeMethods
|
3
3
|
|
4
|
+
module ClassMethods
|
5
|
+
def known_attributes
|
6
|
+
Helpers.get_instance_variable(self, :known_attributes, Set.new)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.extend(ClassMethods)
|
12
|
+
end
|
13
|
+
|
14
|
+
def known_attribute?(attribute)
|
15
|
+
known_attributes.include?(attribute.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def known_attributes
|
19
|
+
@known_attributes ||= self.class.known_attributes.dup
|
20
|
+
end
|
21
|
+
|
4
22
|
def internal_data
|
5
23
|
@internal_data ||= {}
|
6
24
|
end
|
@@ -17,10 +35,6 @@ module SmoothOperator
|
|
17
35
|
end
|
18
36
|
end
|
19
37
|
|
20
|
-
def get_attribute_type(attribute)
|
21
|
-
self.class.internal_structure[attribute.to_s]
|
22
|
-
end
|
23
|
-
|
24
38
|
def push_to_internal_data(attribute_name, attribute_value)
|
25
39
|
attribute_name = attribute_name.to_s
|
26
40
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SmoothOperator
|
2
|
+
module ModelName
|
3
|
+
|
4
|
+
def resources_name(default_bypass = nil)
|
5
|
+
return @resources_name if defined?(@resources_name)
|
6
|
+
|
7
|
+
(Helpers.super_method(self, :resources_name, true) || (default_bypass ? nil : self.resource_name.pluralize))
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_writer :resources_name
|
11
|
+
|
12
|
+
def resource_name(default_bypass = nil)
|
13
|
+
return @resource_name if defined?(@resource_name)
|
14
|
+
|
15
|
+
(Helpers.super_method(self, :resource_name, true) || (default_bypass ? nil : self.model_name.to_s.underscore))
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_writer :resource_name
|
19
|
+
|
20
|
+
def model_name
|
21
|
+
return '' if @_model_name == :none
|
22
|
+
|
23
|
+
if defined? ActiveModel
|
24
|
+
rails_model_name_method
|
25
|
+
else
|
26
|
+
@_model_name ||= name.split('::').last.underscore.capitalize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def model_name=(name)
|
31
|
+
@_model_name = name
|
32
|
+
end
|
33
|
+
|
34
|
+
protected ############## PROTECTED #############
|
35
|
+
|
36
|
+
def rails_model_name_method
|
37
|
+
@model_name ||= begin
|
38
|
+
namespace ||= self.parents.detect do |n|
|
39
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
40
|
+
end
|
41
|
+
|
42
|
+
ActiveModel::Name.new(self, namespace, @_model_name).tap do |model_name|
|
43
|
+
def model_name.human(options = {}); @klass.send(:_translate, "models.#{i18n_key}", options); end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
+
require "smooth_operator/model_name"
|
1
2
|
require "smooth_operator/delegation"
|
2
3
|
require "smooth_operator/validations"
|
3
|
-
require "smooth_operator/model_schema"
|
4
4
|
require "smooth_operator/serialization"
|
5
5
|
require "smooth_operator/attribute_methods"
|
6
6
|
require "smooth_operator/attribute_assignment"
|
@@ -10,9 +10,10 @@ module SmoothOperator
|
|
10
10
|
|
11
11
|
class Base
|
12
12
|
|
13
|
+
extend ModelName
|
14
|
+
|
13
15
|
include Delegation
|
14
16
|
include Validations
|
15
|
-
include ModelSchema
|
16
17
|
include Serialization
|
17
18
|
include AttributeMethods
|
18
19
|
include AttributeAssignment
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SmoothOperator
|
2
|
+
module Schema
|
3
|
+
|
4
|
+
def known_by_schema?(attribute)
|
5
|
+
self.class.internal_structure.include?(attribute.to_s)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_attribute_type(attribute)
|
9
|
+
self.class.internal_structure[attribute.to_s]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
|
18
|
+
attr_writer :resource_name
|
19
|
+
|
20
|
+
def schema(structure)
|
21
|
+
internal_structure.merge! Helpers.stringify_keys(structure)
|
22
|
+
|
23
|
+
known_attributes.merge internal_structure.keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def internal_structure
|
27
|
+
Helpers.get_instance_variable(self, :internal_structure, { "errors" => nil, primary_key => nil, destroy_key => nil })
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/smooth_operator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "smooth_operator/schema"
|
1
2
|
require "smooth_operator/version"
|
2
3
|
require "smooth_operator/helpers"
|
3
4
|
require "smooth_operator/operator"
|
@@ -14,6 +15,7 @@ module SmoothOperator
|
|
14
15
|
extend Relation::Associations
|
15
16
|
extend Translation if defined? I18n
|
16
17
|
|
18
|
+
include Schema
|
17
19
|
include Operator
|
18
20
|
include Persistence
|
19
21
|
include FinderMethods
|
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.20.
|
4
|
+
version: 1.20.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
@@ -91,7 +91,7 @@ files:
|
|
91
91
|
- lib/smooth_operator/delegation.rb
|
92
92
|
- lib/smooth_operator/finder_methods.rb
|
93
93
|
- lib/smooth_operator/helpers.rb
|
94
|
-
- lib/smooth_operator/
|
94
|
+
- lib/smooth_operator/model_name.rb
|
95
95
|
- lib/smooth_operator/open_struct.rb
|
96
96
|
- lib/smooth_operator/operator.rb
|
97
97
|
- lib/smooth_operator/operators/faraday.rb
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/smooth_operator/remote_call/errors/timeout.rb
|
107
107
|
- lib/smooth_operator/remote_call/faraday.rb
|
108
108
|
- lib/smooth_operator/remote_call/typhoeus.rb
|
109
|
+
- lib/smooth_operator/schema.rb
|
109
110
|
- lib/smooth_operator/serialization.rb
|
110
111
|
- lib/smooth_operator/translation.rb
|
111
112
|
- lib/smooth_operator/validations.rb
|
@@ -117,7 +118,7 @@ files:
|
|
117
118
|
- spec/smooth_operator/attributes_dirty_spec.rb
|
118
119
|
- spec/smooth_operator/delegation_spec.rb
|
119
120
|
- spec/smooth_operator/finder_methods_spec.rb
|
120
|
-
- spec/smooth_operator/
|
121
|
+
- spec/smooth_operator/model_name_spec.rb
|
121
122
|
- spec/smooth_operator/operator_spec.rb
|
122
123
|
- spec/smooth_operator/persistence_spec.rb
|
123
124
|
- spec/smooth_operator/remote_call_spec.rb
|
@@ -164,7 +165,7 @@ test_files:
|
|
164
165
|
- spec/smooth_operator/attributes_dirty_spec.rb
|
165
166
|
- spec/smooth_operator/delegation_spec.rb
|
166
167
|
- spec/smooth_operator/finder_methods_spec.rb
|
167
|
-
- spec/smooth_operator/
|
168
|
+
- spec/smooth_operator/model_name_spec.rb
|
168
169
|
- spec/smooth_operator/operator_spec.rb
|
169
170
|
- spec/smooth_operator/persistence_spec.rb
|
170
171
|
- spec/smooth_operator/remote_call_spec.rb
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module SmoothOperator
|
2
|
-
module ModelSchema
|
3
|
-
|
4
|
-
def self.included(base)
|
5
|
-
base.extend(ClassMethods)
|
6
|
-
end
|
7
|
-
|
8
|
-
def known_attribute?(attribute)
|
9
|
-
known_attributes.include?(attribute.to_s)
|
10
|
-
end
|
11
|
-
|
12
|
-
def known_by_schema?(attribute)
|
13
|
-
self.class.internal_structure.include?(attribute.to_s)
|
14
|
-
end
|
15
|
-
|
16
|
-
def known_attributes
|
17
|
-
@known_attributes ||= self.class.known_attributes.dup
|
18
|
-
end
|
19
|
-
|
20
|
-
module ClassMethods
|
21
|
-
|
22
|
-
def resources_name(default_bypass = nil)
|
23
|
-
return @resources_name if defined?(@resources_name)
|
24
|
-
|
25
|
-
(Helpers.super_method(self, :resources_name, true) || (default_bypass ? nil : self.resource_name.pluralize))
|
26
|
-
end
|
27
|
-
attr_writer :resources_name
|
28
|
-
|
29
|
-
def resource_name(default_bypass = nil)
|
30
|
-
return @resource_name if defined?(@resource_name)
|
31
|
-
|
32
|
-
(Helpers.super_method(self, :resource_name, true) || (default_bypass ? nil : self.model_name.to_s.underscore))
|
33
|
-
end
|
34
|
-
attr_writer :resource_name
|
35
|
-
|
36
|
-
def schema(structure)
|
37
|
-
internal_structure.merge! Helpers.stringify_keys(structure)
|
38
|
-
|
39
|
-
known_attributes.merge internal_structure.keys
|
40
|
-
end
|
41
|
-
|
42
|
-
def internal_structure
|
43
|
-
Helpers.get_instance_variable(self, :internal_structure, { "errors" => nil })
|
44
|
-
end
|
45
|
-
|
46
|
-
def known_attributes
|
47
|
-
Helpers.get_instance_variable(self, :known_attributes, Set.new)
|
48
|
-
end
|
49
|
-
|
50
|
-
def model_name
|
51
|
-
return '' if @_model_name == :none
|
52
|
-
|
53
|
-
if defined? ActiveModel
|
54
|
-
rails_model_name_method
|
55
|
-
else
|
56
|
-
@_model_name ||= name.split('::').last.underscore.capitalize
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def model_name=(name)
|
61
|
-
@_model_name = name
|
62
|
-
end
|
63
|
-
|
64
|
-
protected ############## PROTECTED #############
|
65
|
-
|
66
|
-
def rails_model_name_method
|
67
|
-
@model_name ||= begin
|
68
|
-
namespace ||= self.parents.detect do |n|
|
69
|
-
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
70
|
-
end
|
71
|
-
|
72
|
-
ActiveModel::Name.new(self, namespace, @_model_name).tap do |model_name|
|
73
|
-
def model_name.human(options = {}); @klass.send(:_translate, "models.#{i18n_key}", options); end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|