action_handler 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action_handler/config.rb +8 -0
- data/lib/action_handler/equip.rb +4 -0
- data/lib/action_handler/installer.rb +7 -4
- data/lib/action_handler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25a1f7268d1e4a69c5b7b6539add71a3c1de890b16089326be89b8b29df485b5
|
4
|
+
data.tar.gz: 01412c3d175cce1e05361ef8cc1debe36f095bc94588505af64c1f3bded98587
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dc55dca8b126cc3487a7e69b44d34ebdf83a8f0cd27b91dc1afe111f932e8e45166d226ea4d7ae6695c8111cb669ecbf7b6cf84629f7a784da608eb60284ee6
|
7
|
+
data.tar.gz: e6812ff0295766d8e8bb55026d032dacf57bdd744b3f3feca197d24def657eae0cb08ef9c17365a40f322f2546e9b724a05e2c8acae87b8a8112c2393a709977
|
@@ -14,16 +14,24 @@ module ActionHandler
|
|
14
14
|
handler_class.instance_variable_set(CONFIG_VAR_NAME, config)
|
15
15
|
end
|
16
16
|
|
17
|
+
attr_reader :as_controller
|
17
18
|
attr_reader :action_methods
|
18
19
|
attr_reader :args_suppliers
|
19
20
|
attr_reader :custom_args
|
20
21
|
|
21
22
|
def initialize
|
23
|
+
@as_controller = nil
|
22
24
|
@action_methods = nil
|
23
25
|
@args_suppliers = []
|
24
26
|
@custom_args = {} # { method_name: proc }
|
25
27
|
end
|
26
28
|
|
29
|
+
def as_controller=(block)
|
30
|
+
raise ArgumentError, 'must be proc' unless block.is_a?(Proc)
|
31
|
+
|
32
|
+
@as_controller = block
|
33
|
+
end
|
34
|
+
|
27
35
|
def action_methods=(names)
|
28
36
|
raise ArgumentError, 'must be array' unless names.is_a?(Array)
|
29
37
|
|
data/lib/action_handler/equip.rb
CHANGED
@@ -35,6 +35,10 @@ module ActionHandler
|
|
35
35
|
end
|
36
36
|
|
37
37
|
module HandlerExtension
|
38
|
+
def as_controller(&block)
|
39
|
+
ActionHandler::Config.get(self).as_controller = block
|
40
|
+
end
|
41
|
+
|
38
42
|
def action_methods(*method_names)
|
39
43
|
ActionHandler::Config.get(self).action_methods = method_names
|
40
44
|
end
|
@@ -26,11 +26,14 @@ module ActionHandler
|
|
26
26
|
|
27
27
|
installer = self
|
28
28
|
initializer = Module.new.tap do |m|
|
29
|
-
m.
|
30
|
-
super(*args)
|
29
|
+
m.send(:define_method, :initialize) do |*args|
|
31
30
|
factory = self.class.instance_variable_get(:@_action_handler_factory)
|
32
|
-
handler = factory.call
|
31
|
+
handler = factory.call
|
32
|
+
config = ActionHandler::Config.get(handler.class)
|
33
|
+
self.class.class_eval(&config.as_controller) if config&.as_controller
|
33
34
|
installer.send(:setup, self, handler)
|
35
|
+
|
36
|
+
super(*args)
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
@@ -49,7 +52,7 @@ module ActionHandler
|
|
49
52
|
# If we use `define_singleton_method`, methods don't work correctly.
|
50
53
|
# I don't know Rails internal details but
|
51
54
|
# Rails requires methods to be defined in a class.
|
52
|
-
ctrl.class.define_method
|
55
|
+
ctrl.class.send(:define_method, name) do
|
53
56
|
method = handler.method(name)
|
54
57
|
args = installer.args_maker.make_args(method, args_supplier, context: self)
|
55
58
|
res = method.call(*args)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryym
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|