arq 0.3.0 → 0.3.1
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/arq/action.rb +13 -10
 - data/lib/arq/action_module_hash.rb +44 -0
 - data/lib/arq/version.rb +1 -1
 - data/lib/arq.rb +1 -1
 - metadata +3 -3
 - data/lib/arq/module_hash.rb +0 -38
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a0ee16565eecb2e2866939a75dae3fde195f0c941bddb66f43f98ccc92c0e642
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2e4ca8c155a462706ca2668b18bac36c38fac84b025f00f4b59f54d0d478a382
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
       124 
     | 
    
         
            -
                     
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                     
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
      
 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
    
    
    
        data/lib/arq.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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. 
     | 
| 
      
 51 
     | 
    
         
            +
            rubygems_version: 3.3.7
         
     | 
| 
       52 
52 
     | 
    
         
             
            signing_key:
         
     | 
| 
       53 
53 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       54 
54 
     | 
    
         
             
            summary: A simple service skeleton framework
         
     | 
    
        data/lib/arq/module_hash.rb
    DELETED
    
    | 
         @@ -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
         
     |