smooth_operator 1.2.5 → 1.2.6
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 +2 -8
- data/lib/smooth_operator/relation/array_relation.rb +20 -4
- data/lib/smooth_operator/relation/associations.rb +43 -48
- data/lib/smooth_operator/version.rb +1 -1
- data/lib/smooth_operator.rb +1 -1
- metadata +1 -2
- data/lib/smooth_operator/relation/single_relation.rb +0 -21
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
OTQyODc3MjY2NmU2MTlkYTU2NzM0MTRjMjUxYTY0MGRlMDEzNjU5NA==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MDI2NmM2NTYxODllNzRmOWE0ZTAxZjM5NTYzOGIzNmIxMTg1ZmJiZA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
YWJlMjY1OGI1NmY2NjJhMmVkNzI4YjNmZjYyZWFhMGM5NDNkZWNiYWVlMWZm
|
|
10
|
+
Mzg5MjQ4MTIxOTYxZDVhZmQ4OTQzMjc2YzdkOWI3MjhlMzAzZDg4Y2ZjOTdl
|
|
11
|
+
NDU1MzMyZWY0MWE3N2Q3YzhiNWQ2N2QxNDI5NDNkNWY1NjMwMGU=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
YjU2NTgxMjlhODFhZjUyOWUyM2I0NzZkYmQ1NTgwMjI5ZGJkZDZkZjViYThi
|
|
14
|
+
YTJjZmZlYjhlZTNiMjA4MzJmMDc2NWE2MWU5NjI4MmQxODdmYzYxMGQ0N2Qz
|
|
15
|
+
NDZkM2Q2ZWQ1YmNlOGJlM2EyYTVkNTBkZTA1NzljMGU1ZDZiZTY=
|
|
@@ -3,11 +3,7 @@ module SmoothOperator
|
|
|
3
3
|
module Delegation
|
|
4
4
|
|
|
5
5
|
def respond_to?(method, include_private = false)
|
|
6
|
-
|
|
7
|
-
true
|
|
8
|
-
else
|
|
9
|
-
self.class.reflect_on_association(method) ? true : super
|
|
10
|
-
end
|
|
6
|
+
known_attribute?(method) ? true : super
|
|
11
7
|
end
|
|
12
8
|
|
|
13
9
|
def method_missing(method, *args, &block)
|
|
@@ -21,9 +17,7 @@ module SmoothOperator
|
|
|
21
17
|
when :setter
|
|
22
18
|
return push_to_internal_data(method_name, args.first)
|
|
23
19
|
else
|
|
24
|
-
if
|
|
25
|
-
return get_relation(method_name)
|
|
26
|
-
elsif !self.class.strict_behaviour || known_attribute?(method_name)
|
|
20
|
+
if !self.class.strict_behaviour || known_attribute?(method_name)
|
|
27
21
|
return get_internal_data(method_name)
|
|
28
22
|
end
|
|
29
23
|
end
|
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
require "smooth_operator/relation/single_relation"
|
|
2
|
-
|
|
3
1
|
module SmoothOperator
|
|
4
2
|
module Relation
|
|
5
|
-
class ArrayRelation
|
|
3
|
+
class ArrayRelation
|
|
4
|
+
|
|
5
|
+
attr_reader :object, :association
|
|
6
|
+
|
|
7
|
+
def initialize(object, association)
|
|
8
|
+
@object, @association = object, association
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def method_missing(method, *args, &block)
|
|
12
|
+
data.respond_to?(method) ? data.send(method, *args) : super
|
|
13
|
+
end
|
|
6
14
|
|
|
7
15
|
def data
|
|
8
|
-
|
|
16
|
+
data = object.get_internal_data(association.to_s)
|
|
17
|
+
|
|
18
|
+
data.nil? ? [] : [*data]
|
|
9
19
|
end
|
|
10
20
|
|
|
11
21
|
def reload
|
|
12
22
|
"TODO"
|
|
13
23
|
end
|
|
14
24
|
|
|
25
|
+
def new(attributes = {})
|
|
26
|
+
object.class.reflect_on_association(association).klass.new(attributes)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
alias :build :new
|
|
30
|
+
|
|
15
31
|
end
|
|
16
32
|
end
|
|
17
33
|
end
|
|
@@ -5,81 +5,76 @@ module SmoothOperator
|
|
|
5
5
|
module Relation
|
|
6
6
|
module Associations
|
|
7
7
|
|
|
8
|
-
def
|
|
9
|
-
|
|
8
|
+
def has_many(nested_object_name, options = {})
|
|
9
|
+
accepts_nested_objects(nested_object_name, :has_many, options)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
relations[relation_name]
|
|
15
|
-
else
|
|
16
|
-
relations[relation_name] = build_relation(relation_name)
|
|
17
|
-
end
|
|
12
|
+
def has_one(nested_object_name, options = {})
|
|
13
|
+
accepts_nested_objects(nested_object_name, :has_one, options)
|
|
18
14
|
end
|
|
19
15
|
|
|
20
|
-
def
|
|
21
|
-
|
|
16
|
+
def belongs_to(nested_object_name, options = {})
|
|
17
|
+
accepts_nested_objects(nested_object_name, :belongs_to, options)
|
|
22
18
|
end
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
def reflections
|
|
21
|
+
Helpers.get_instance_variable(self, :reflections, {})
|
|
22
|
+
end
|
|
25
23
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
ArrayRelation.new(self, relation_name)
|
|
29
|
-
elsif Helpers.present? get_internal_data(relation_name)
|
|
30
|
-
SingleRelation.new(self, relation_name)
|
|
31
|
-
else
|
|
32
|
-
nil
|
|
33
|
-
end
|
|
24
|
+
def reflect_on_association(association)
|
|
25
|
+
reflections[association]
|
|
34
26
|
end
|
|
35
27
|
|
|
36
|
-
|
|
28
|
+
def reflect_on_all_associations(macro = nil)
|
|
29
|
+
macro ? reflections.values.select { |reflection| reflection.macro == macro } : reflections.values
|
|
30
|
+
end
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
accepts_nested_objects(nested_object_name, :has_many, options)
|
|
40
|
-
end
|
|
32
|
+
protected ###################### PROTECTED ###################
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end
|
|
34
|
+
def accepts_nested_objects(association, macro, options = {})
|
|
35
|
+
options = parse_options(options, { macro: macro })
|
|
45
36
|
|
|
46
|
-
|
|
47
|
-
accepts_nested_objects(nested_object_name, :belongs_to, options)
|
|
48
|
-
end
|
|
37
|
+
reflection = AssociationReflection.new(association, Reflection.new(name, {}), options)
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
Helpers.get_instance_variable(self, :reflections, {})
|
|
52
|
-
end
|
|
39
|
+
schema(association => reflection.klass)
|
|
53
40
|
|
|
54
|
-
|
|
55
|
-
reflections[association]
|
|
56
|
-
end
|
|
41
|
+
reflections.merge!(association => reflection)
|
|
57
42
|
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
if reflection.has_many?
|
|
44
|
+
define_has_many_association_method(reflection, association)
|
|
45
|
+
else
|
|
46
|
+
define_single_association_method(reflection, association)
|
|
60
47
|
end
|
|
48
|
+
end
|
|
61
49
|
|
|
62
|
-
|
|
50
|
+
private ####################### PRIVATE ######################
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
def define_has_many_association_method(reflection, association)
|
|
53
|
+
define_method(association) do
|
|
54
|
+
array_relation = instance_variable_get("@#{association}")
|
|
66
55
|
|
|
67
|
-
|
|
56
|
+
if array_relation.nil?
|
|
57
|
+
array_relation = ArrayRelation.new(self, association)
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
instance_variable_set("@#{association}", array_relation)
|
|
60
|
+
end
|
|
70
61
|
|
|
71
|
-
|
|
62
|
+
array_relation
|
|
72
63
|
end
|
|
64
|
+
end
|
|
73
65
|
|
|
74
|
-
|
|
66
|
+
def define_single_association_method(reflection, association)
|
|
67
|
+
define_method(association) { get_internal_data(association.to_s) }
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
define_method("build_#{reflection.single_name}") { |attributes = {}| reflection.klass.new(attributes) }
|
|
70
|
+
end
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
def parse_options(options, default_options)
|
|
73
|
+
options = options.is_a?(Hash) ? options.merge(default_options) : default_options
|
|
81
74
|
|
|
75
|
+
Helpers.symbolyze_keys(options)
|
|
82
76
|
end
|
|
77
|
+
|
|
83
78
|
end
|
|
84
79
|
end
|
|
85
80
|
end
|
data/lib/smooth_operator.rb
CHANGED
|
@@ -11,12 +11,12 @@ module SmoothOperator
|
|
|
11
11
|
class Base < OpenStruct::Base
|
|
12
12
|
|
|
13
13
|
extend FinderMethods
|
|
14
|
+
extend Relation::Associations
|
|
14
15
|
extend Translation if defined? I18n
|
|
15
16
|
|
|
16
17
|
include Operator
|
|
17
18
|
include Persistence
|
|
18
19
|
include FinderMethods
|
|
19
|
-
include Relation::Associations
|
|
20
20
|
|
|
21
21
|
self.strict_behaviour = true
|
|
22
22
|
|
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.2.
|
|
4
|
+
version: 1.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- João Gonçalves
|
|
@@ -100,7 +100,6 @@ files:
|
|
|
100
100
|
- lib/smooth_operator/relation/association_reflection.rb
|
|
101
101
|
- lib/smooth_operator/relation/associations.rb
|
|
102
102
|
- lib/smooth_operator/relation/reflection.rb
|
|
103
|
-
- lib/smooth_operator/relation/single_relation.rb
|
|
104
103
|
- lib/smooth_operator/remote_call/base.rb
|
|
105
104
|
- lib/smooth_operator/remote_call/errors/connection_failed.rb
|
|
106
105
|
- lib/smooth_operator/remote_call/errors/timeout.rb
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module SmoothOperator
|
|
2
|
-
module Relation
|
|
3
|
-
class SingleRelation
|
|
4
|
-
|
|
5
|
-
attr_reader :object, :relation_name
|
|
6
|
-
|
|
7
|
-
def initialize(object, relation_name)
|
|
8
|
-
@object, @relation_name = object, relation_name
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def method_missing(method, *args, &block)
|
|
12
|
-
data.respond_to?(method) ? data.send(method, *args) : super
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def data
|
|
16
|
-
object.get_internal_data(relation_name)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|