light_operations 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/light_operations/core.rb +1 -1
- data/lib/light_operations/version.rb +1 -1
- metadata +1 -2
- data/lib/light_operations/crud_core.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daff2324f298c8c3565ac162ad4f898b46a67444
|
4
|
+
data.tar.gz: c29a35d3bb49d0f939dd0ceda12d7199bf818af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e49fc15fc00e7a754d7cbcf9d1b42543b01ab1233916e57af9238453de7f222e55d7d515d49b6bebaa15f00856a773fb46f2fe728f4d203ee86e460d0ecfa377
|
7
|
+
data.tar.gz: 75f5551894d511923473fd6644c836510586b1a74f0bfdcb0b04e22da3b8127493146102deb57b7d7d7714d1c3e6dd4751b47b843d62b040ee40e919be9a7ea7
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light_operations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pawel Niemczyk
|
@@ -154,7 +154,6 @@ files:
|
|
154
154
|
- Rakefile
|
155
155
|
- lib/light_operations.rb
|
156
156
|
- lib/light_operations/core.rb
|
157
|
-
- lib/light_operations/crud_core.rb
|
158
157
|
- lib/light_operations/version.rb
|
159
158
|
- light_operations.gemspec
|
160
159
|
- spec/lib/core_spec.rb
|
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module CrudOperations
|
4
|
-
class Core
|
5
|
-
include ::ActiveSupport::Rescuable
|
6
|
-
MissingDependency = Class.new(StandardError)
|
7
|
-
|
8
|
-
attr_reader :dependencies, :bind_object, :subject
|
9
|
-
|
10
|
-
def initialize(dependencies = {})
|
11
|
-
@dependencies = dependencies
|
12
|
-
end
|
13
|
-
|
14
|
-
# do no.t override this method
|
15
|
-
def run(params = {})
|
16
|
-
clear_subject_with_errors!
|
17
|
-
@subject = execute(params)
|
18
|
-
execute_actions
|
19
|
-
self
|
20
|
-
rescue => exception
|
21
|
-
rescue_with_handler(exception) || raise
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def on_success(binded_method = nil, &block)
|
26
|
-
actions[:success] = binded_method || block
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def on_fail(binded_method = nil, &block)
|
31
|
-
actions[:fail] = binded_method || block
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def on(actions_with_responses = {})
|
36
|
-
actions_assign(actions_with_responses, :success, :fail)
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def clear!
|
41
|
-
clear_actions!
|
42
|
-
unbind!
|
43
|
-
clear_subject_with_errors!
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
def unbind!
|
48
|
-
@bind_object = nil
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
def clear_subject_with_errors!
|
53
|
-
@subject, @fail_errors, @errors = nil, nil, nil
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
def clear_actions!
|
58
|
-
@actions = {}
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
def bind_with(bind_object)
|
63
|
-
@bind_object = bind_object
|
64
|
-
self
|
65
|
-
end
|
66
|
-
|
67
|
-
def errors
|
68
|
-
@errors ||= fail_errors || (subject.respond_to?(:errors) ? subject.errors : [])
|
69
|
-
end
|
70
|
-
|
71
|
-
def fail?
|
72
|
-
!success?
|
73
|
-
end
|
74
|
-
|
75
|
-
def success?
|
76
|
-
errors.respond_to?(:empty?) ? errors.empty? : !errors
|
77
|
-
end
|
78
|
-
|
79
|
-
protected
|
80
|
-
|
81
|
-
attr_reader :fail_errors
|
82
|
-
|
83
|
-
def actions_assign(hash, *keys)
|
84
|
-
keys.each { |key| actions[key] = hash[key] if hash.key?(key) }
|
85
|
-
end
|
86
|
-
|
87
|
-
def execute_actions
|
88
|
-
success? ? execute_success_action : execute_fail_action
|
89
|
-
end
|
90
|
-
|
91
|
-
def execute_success_action
|
92
|
-
return unless actions.key?(:success)
|
93
|
-
action = actions[:success]
|
94
|
-
bind_object.send(action, subject) if action.is_a?(Symbol) && bind_object
|
95
|
-
action.call(subject) if action.is_a?(Proc)
|
96
|
-
end
|
97
|
-
|
98
|
-
def execute_fail_action
|
99
|
-
return unless actions.key?(:fail)
|
100
|
-
action = actions[:fail]
|
101
|
-
bind_object.send(action, subject, errors) if action.is_a?(Symbol) && bind_object
|
102
|
-
action.call(subject, errors) if action.is_a?(Proc)
|
103
|
-
end
|
104
|
-
|
105
|
-
def fail!(errors = [])
|
106
|
-
@errors = nil
|
107
|
-
@fail_errors = errors
|
108
|
-
end
|
109
|
-
|
110
|
-
def actions
|
111
|
-
@actions ||= {}
|
112
|
-
end
|
113
|
-
|
114
|
-
def execute(_params = {})
|
115
|
-
fail 'Not implemented yet'
|
116
|
-
end
|
117
|
-
|
118
|
-
def dependency(name)
|
119
|
-
dependencies.fetch(name)
|
120
|
-
rescue KeyError => e
|
121
|
-
raise MissingDependency, e.message
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|