smooth_operator 1.2.6 → 1.2.7
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
|
-
|
4
|
+
YTM5NDgwNzg0NmI2ZTkwNTg5Y2RlMGI2NDY0ZDdjMzhiNjE2NTRhYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWJkNmU3ZjRjMGRkYjA2M2QyMWQzMGNhMWMwODFlYWIyNjYxNTgzYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWIxMWJhYWJiY2U1ZjM5YzBhOTVhMzUwZjNjODYzYzMxZWVhODQ2YzNjNDdj
|
10
|
+
OGNkM2MzYTNlYTUyODhhNTlhYzBjOTcwMDhiZTNlYjk3MzJjZjkzZWNlN2U5
|
11
|
+
YjZhMzhmZjM3NzYxN2E2NjI2NWUyMjhlNzI5NTBjNDZlODFmZmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGMyNmQ4ZTc1ZGVhMzAxNjE2M2E0ZmYyODMwZGY3YjQzMGVkMmI5MDVmZTMy
|
14
|
+
NDAyYjlhZDZhNTM4MDFlNDkxMWU5ODMzZTkzODBmODVjZWZlYmZhOWJhNGE1
|
15
|
+
MDViZjNiMjk0MjNmNTNjM2MwYjVlODI1MDg0ZTYyNmU2NDRhMzY=
|
@@ -28,8 +28,6 @@ module SmoothOperator
|
|
28
28
|
|
29
29
|
known_attributes.add attribute_name
|
30
30
|
|
31
|
-
attribute_name, attribute_value = extract_nested_attributes(attribute_name, attribute_value)
|
32
|
-
|
33
31
|
initiate_or_update_internal_data(attribute_name, attribute_value)
|
34
32
|
|
35
33
|
new_record_or_mark_for_destruction?(attribute_name, attribute_value)
|
@@ -37,18 +35,6 @@ module SmoothOperator
|
|
37
35
|
|
38
36
|
protected #################### PROTECTED METHODS DOWN BELOW ######################
|
39
37
|
|
40
|
-
def extract_nested_attributes(attribute_name, attribute_value)
|
41
|
-
if !!(attribute_name =~ /_attributes$/)
|
42
|
-
attribute_name = attribute_name[0..-12]
|
43
|
-
|
44
|
-
if self.class.reflect_on_association(attribute_name.to_sym).has_many?
|
45
|
-
attribute_value = attribute_value.values
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
[attribute_name, attribute_value]
|
50
|
-
end
|
51
|
-
|
52
38
|
def initiate_or_update_internal_data(attribute_name, attribute_value)
|
53
39
|
if internal_data[attribute_name].nil?
|
54
40
|
initiate_internal_data(attribute_name, attribute_value)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SmoothOperator
|
2
2
|
module Relation
|
3
|
-
class ArrayRelation
|
3
|
+
class ArrayRelation < ::SimpleDelegator
|
4
4
|
|
5
5
|
attr_reader :object, :association
|
6
6
|
|
@@ -8,16 +8,6 @@ module SmoothOperator
|
|
8
8
|
@object, @association = object, association
|
9
9
|
end
|
10
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
|
-
data = object.get_internal_data(association.to_s)
|
17
|
-
|
18
|
-
data.nil? ? [] : [*data]
|
19
|
-
end
|
20
|
-
|
21
11
|
def reload
|
22
12
|
"TODO"
|
23
13
|
end
|
@@ -28,6 +18,14 @@ module SmoothOperator
|
|
28
18
|
|
29
19
|
alias :build :new
|
30
20
|
|
21
|
+
protected ############### PROTECTED ###############
|
22
|
+
|
23
|
+
def refresh
|
24
|
+
data = object.get_internal_data(association.to_s)
|
25
|
+
|
26
|
+
__setobj__(data.nil? ? [] : [*data])
|
27
|
+
end
|
28
|
+
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -45,6 +45,10 @@ module SmoothOperator
|
|
45
45
|
else
|
46
46
|
define_single_association_method(reflection, association)
|
47
47
|
end
|
48
|
+
|
49
|
+
self.send(:attr_reader, "#{association}_attributes".to_sym)
|
50
|
+
|
51
|
+
define_attributes_setter_methods(reflection, association)
|
48
52
|
end
|
49
53
|
|
50
54
|
private ####################### PRIVATE ######################
|
@@ -59,6 +63,8 @@ module SmoothOperator
|
|
59
63
|
instance_variable_set("@#{association}", array_relation)
|
60
64
|
end
|
61
65
|
|
66
|
+
array_relation.send(:refresh)
|
67
|
+
|
62
68
|
array_relation
|
63
69
|
end
|
64
70
|
end
|
@@ -69,6 +75,16 @@ module SmoothOperator
|
|
69
75
|
define_method("build_#{reflection.single_name}") { |attributes = {}| reflection.klass.new(attributes) }
|
70
76
|
end
|
71
77
|
|
78
|
+
def define_attributes_setter_methods(reflection, association)
|
79
|
+
define_method("#{association}_attributes=") do |attributes|
|
80
|
+
instance_variable_set("@#{association}_attributes", attributes)
|
81
|
+
|
82
|
+
attributes = attributes.values if reflection.has_many?
|
83
|
+
|
84
|
+
push_to_internal_data(association.to_s, attributes)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
72
88
|
def parse_options(options, default_options)
|
73
89
|
options = options.is_a?(Hash) ? options.merge(default_options) : default_options
|
74
90
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|