arq 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf6593b58efb70d3d2ac268f33cb8eae378fe821d13e69975c13216cdfe1ff2f
4
- data.tar.gz: fa4401c24cd50c2d8a5b6f7adb69e3224e126d75c166fca994f816ceb27e4523
3
+ metadata.gz: a0ee16565eecb2e2866939a75dae3fde195f0c941bddb66f43f98ccc92c0e642
4
+ data.tar.gz: 2e4ca8c155a462706ca2668b18bac36c38fac84b025f00f4b59f54d0d478a382
5
5
  SHA512:
6
- metadata.gz: a9feae6ec6e4ff17c37a2af7d99b7df6ec22e1d1fce6af04e42444bdff3e250b44e2c8036d64b333620929cd0d75bd5e0f69058e09d190dc49438ca2e2d456d9
7
- data.tar.gz: 297f51c062e329349999b9b370c1f1fc91ba17f90e2b57baf141fc44df6aae3ae97086eef293108204417b94143814ba1e8f512deb9f89d31022c7eb37e5287d
6
+ metadata.gz: 047d23d860d49a35f90564695578e776b35e3628d9f53681de8db4d2c4eaee407a8bae985983015c2e843e67bc70857e1ad173dfbb93d081cfeb9fdd7cf87dd8
7
+ data.tar.gz: 34f0ca90c2783f25623c1dfd464e7e4b7dce0677e187647678876aad0a5927b856bc77ed6e3d75bfd460a76f2488f0a5e9f084e6a80f3f76b23bb8ab5b5e7238
data/lib/arq/action.rb CHANGED
@@ -117,18 +117,21 @@ module Arq
117
117
  @_ctx.fail_now!(message)
118
118
  end
119
119
 
120
- # Used to easily call other actions via snake-cased modules and dot accessors.
120
+ # Used to easily call other actions via snake-cased paths with dot accessors.
121
121
  # IE `Foo::Bar::Action` can be called via `foo.bar.action`
122
122
  def method_missing(method, *args, &block)
123
- obj = Object.const_get(method.to_s.camelize)
124
- case obj
125
- when Arq::Action
126
- call_other(obj)
127
- when Module
128
- Arq::ModuleHash.new(obj, self)
129
- end
130
- rescue NameError => _e
131
- super
123
+ # Format method as module path.
124
+ formatted = method.to_s.camelize
125
+
126
+ # Attempt to find object.
127
+ obj = if Object.const_defined?(formatted)
128
+ Object.const_get(formatted)
129
+ else
130
+ return super
131
+ end
132
+
133
+ # Defer handling to ActionModuleHash
134
+ Arq::ActionModuleHash.from(obj, self)
132
135
  end
133
136
 
134
137
  def respond_to_missing?(method, include_private: false)
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arq
4
+ # Allows for dot-accessing of modules and running of actions.
5
+ # Child modules are automatically wrapped and actions are called.
6
+ class ActionModuleHash < Hash
7
+ # Calls action or wraps in hash class if module.
8
+ def self.from(obj, action_inst)
9
+ case obj
10
+ when Arq::Action
11
+ action_inst.call_other(obj)
12
+ when Module
13
+ new(obj, action_inst)
14
+ else
15
+ raise "Object must be an Action or Module"
16
+ end
17
+ end
18
+
19
+ def initialize(mod, action_inst)
20
+ super()
21
+
22
+ @module = mod
23
+ @action_inst = action_inst
24
+ end
25
+
26
+ def method_missing(method, *args, &block)
27
+ # Format method as module path.
28
+ formatted = method.to_s.camelize
29
+
30
+ # Attempt to find object.
31
+ obj = if Object.const_defined?(formatted)
32
+ Object.const_get(formatted)
33
+ else
34
+ return super
35
+ end
36
+
37
+ self.class.from(obj)
38
+ end
39
+
40
+ def respond_to_missing?(method, include_private = false)
41
+ @module.const_defined?(method.to_s.camelize.to_sym) || super
42
+ end
43
+ end
44
+ end
data/lib/arq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arq
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/arq.rb CHANGED
@@ -5,5 +5,5 @@ require "active_support/core_ext/string"
5
5
  require_relative "arq/version"
6
6
  require_relative "arq/errors"
7
7
  require_relative "arq/context"
8
- require_relative "arq/module_hash"
8
+ require_relative "arq/action_module_hash"
9
9
  require_relative "arq/action"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kavin Phan
@@ -20,9 +20,9 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - lib/arq.rb
22
22
  - lib/arq/action.rb
23
+ - lib/arq/action_module_hash.rb
23
24
  - lib/arq/context.rb
24
25
  - lib/arq/errors.rb
25
- - lib/arq/module_hash.rb
26
26
  - lib/arq/version.rb
27
27
  homepage: https://github.com/kphan32/arq
28
28
  licenses:
@@ -48,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubygems_version: 3.2.32
51
+ rubygems_version: 3.3.7
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: A simple service skeleton framework
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Arq
4
- # Allows for dot-accessing of modules.
5
- # Child modules are automatically wrapped and actions are called.
6
- class ModuleHash < Hash
7
- def initialize(mod, action_inst)
8
- super()
9
-
10
- @module = mod
11
- @action_inst = action_inst
12
- end
13
-
14
- def method_missing(method, *args, &block)
15
- wrap(@module.const_get(method.to_s.camelize))
16
- rescue NameError => _e
17
- super
18
- end
19
-
20
- def respond_to_missing?(method, include_private = false)
21
- @module.const_defined?(method.to_s.camelize.to_sym) || super
22
- end
23
-
24
- private
25
-
26
- # If the value is a Module, it's returned as a ModuleHash.
27
- def wrap(value)
28
- case value
29
- when Arq::Action
30
- @action_inst.call_other(value)
31
- when Module
32
- self.class.new(value, @action_inst)
33
- else
34
- value
35
- end
36
- end
37
- end
38
- end