active_record_decorator 0.0.1 → 0.0.2
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 +4 -4
- data/lib/active_record_decorator.rb +57 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bab50fddd7b8d28eb6e78df3e9ed45bffdf109be82f1a8a45fd2ab5227e1f0b
|
4
|
+
data.tar.gz: 90377dc30a8035a5eef308f596fb76541e737759ea8a9d5c3e5f4593a9410a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be90ac7a3fb6256e21506063dcd0f9a4b16a8f7d56fc269f184c256d32aec24fca650b43b9e27bc3779d39339830243e0f654c9816b277a2adfe17ce5e914a2
|
7
|
+
data.tar.gz: cecb6ff03106f90b6827a09dae8b1038ddba87b26d070730d9ad5774633e1edfff40eafec7d48c8644a972d716db866b20e858f12897cc78f9cb9b9f3a72d3a1
|
@@ -1,4 +1,12 @@
|
|
1
1
|
|
2
|
+
require 'active_record_decorator/assign_operation'
|
3
|
+
require 'active_record_decorator/assign_operation_core/operation'
|
4
|
+
require 'active_record_decorator/condition_evaluator'
|
5
|
+
require 'active_record_decorator/condition_alias_manager'
|
6
|
+
require 'active_record_decorator/condition_evaluator_core/condition'
|
7
|
+
require 'active_record_decorator/condition_evaluator_core/operators'
|
8
|
+
require 'active_record_decorator/condition_evaluator_core/value_object'
|
9
|
+
|
2
10
|
module ActiveRecordDecorator
|
3
11
|
extend ActiveSupport::Concern
|
4
12
|
|
@@ -24,8 +32,10 @@ module ActiveRecordDecorator
|
|
24
32
|
end
|
25
33
|
|
26
34
|
included do
|
27
|
-
class_attribute :relation_callback_chain
|
35
|
+
class_attribute :relation_callback_chain, :condition_aliases, :assign_operation_aliases
|
28
36
|
self.relation_callback_chain = Concurrent::Array.new
|
37
|
+
self.condition_aliases = Concurrent::Array.new
|
38
|
+
self.assign_operation_aliases = Concurrent::Array.new
|
29
39
|
|
30
40
|
# Return self if false else self with passed scoped attached
|
31
41
|
# @param[condition] - deciding condition true/false to attach scope
|
@@ -78,6 +88,43 @@ module ActiveRecordDecorator
|
|
78
88
|
end
|
79
89
|
return status
|
80
90
|
end
|
91
|
+
|
92
|
+
def condition_alias(condition_name, *attributes)
|
93
|
+
|
94
|
+
defaults = attributes.extract_options!.dup
|
95
|
+
condition_name = condition_name
|
96
|
+
operator = defaults[:operator]
|
97
|
+
attr = defaults[:attr]
|
98
|
+
value = defaults[:value]
|
99
|
+
return if self.condition_aliases.detect { |rl| rl.name == condition_name }
|
100
|
+
self.condition_aliases << ConditionEvaluatorCore::Condition.new(condition_name, attr, operator, value)
|
101
|
+
end
|
102
|
+
|
103
|
+
def all_condition_aliases
|
104
|
+
self.condition_aliases
|
105
|
+
end
|
106
|
+
|
107
|
+
def assign_operation(name, *attributes)
|
108
|
+
defaults = attributes.extract_options!.dup
|
109
|
+
|
110
|
+
condition_name = name
|
111
|
+
|
112
|
+
if self.instance_methods(false).include?(condition_name.to_sym)
|
113
|
+
raise "already method defined"
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
attr = defaults[:attr]
|
118
|
+
value = defaults[:value]
|
119
|
+
return if self.assign_operation_aliases.detect { |rl| rl.name == condition_name }
|
120
|
+
self.assign_operation_aliases << AssignOperationCore::Operation.new(condition_name, attr, value)
|
121
|
+
delegate name.to_sym, to: :assign_operation_proxy
|
122
|
+
end
|
123
|
+
|
124
|
+
def all_assign_operation_aliases
|
125
|
+
self.assign_operation_aliases
|
126
|
+
end
|
127
|
+
|
81
128
|
end
|
82
129
|
|
83
130
|
def run_callbacks_registered()
|
@@ -98,4 +145,13 @@ module ActiveRecordDecorator
|
|
98
145
|
end
|
99
146
|
end
|
100
147
|
end
|
148
|
+
|
149
|
+
def condition_match?(condition_to_evaluate)
|
150
|
+
ActiveRecordDecorator::ConditionEvaluator.new(record: self, condition_to_evaluate: condition_to_evaluate).evaluate
|
151
|
+
end
|
152
|
+
|
153
|
+
def assign_operation_proxy
|
154
|
+
@assign_operation_proxy ||= ActiveRecordDecorator::AssignOperation.new(record: self)
|
155
|
+
end
|
156
|
+
|
101
157
|
end
|