composable_operations 0.3.1 → 0.4.0
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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 97911633d5ea509cebc6b53b4e91a2c8421c4e5c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 662c859656c3eb13d791c789d3f9c01b6c8d9610
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5c0b471dc118210b6a3d01ce044aee797fbe8ec6cdf63796e310f7238d1955ec542b6d5f7f876f5efda312d2fb7b3cc1d970c4f7f2798fcbb298a319b49c68c6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 39062f7008cc98ae5b4a060d355cf8f011f3093b94f5580a8217cb56a6bca6da3b7cedad15aa78fd31ded75d9c5f09246fce73f4680f8d6cc58672a57026f3d0
         
     | 
| 
         @@ -1,22 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ComposableOperations
         
     | 
| 
       2 
2 
     | 
    
         
             
              class ComposedOperation < Operation
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
                class  
     | 
| 
      
 4 
     | 
    
         
            +
                class OperationFactory < SimpleDelegator
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                  def initialize(operation_class, options = {})
         
     | 
| 
       7 
7 
     | 
    
         
             
                    super(operation_class)
         
     | 
| 
       8 
     | 
    
         
            -
                    @ 
     | 
| 
      
 8 
     | 
    
         
            +
                    @_options = options
         
     | 
| 
       9 
9 
     | 
    
         
             
                  end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                  def  
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def create(context, input = nil)
         
     | 
| 
      
 12 
     | 
    
         
            +
                    new input, Hash[Hash(@_options).map do |key, value|
         
     | 
| 
      
 13 
     | 
    
         
            +
                      [key, value.kind_of?(Proc) ? context.instance_exec(&value) : value]
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end]
         
     | 
| 
       14 
15 
     | 
    
         
             
                  end
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  protected
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                    attr_reader :__options__
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
17 
     | 
    
         
             
                end
         
     | 
| 
       21 
18 
     | 
    
         | 
| 
       22 
19 
     | 
    
         
             
                class << self
         
     | 
| 
         @@ -26,7 +23,7 @@ module ComposableOperations 
     | 
|
| 
       26 
23 
     | 
    
         
             
                  end
         
     | 
| 
       27 
24 
     | 
    
         | 
| 
       28 
25 
     | 
    
         
             
                  def use(operation, options = {})
         
     | 
| 
       29 
     | 
    
         
            -
                    (@operations ||= []) <<  
     | 
| 
      
 26 
     | 
    
         
            +
                    (@operations ||= []) << OperationFactory.new(operation, options)
         
     | 
| 
       30 
27 
     | 
    
         
             
                  end
         
     | 
| 
       31 
28 
     | 
    
         | 
| 
       32 
29 
     | 
    
         
             
                  def compose(*operations, &block)
         
     | 
| 
         @@ -48,9 +45,8 @@ module ComposableOperations 
     | 
|
| 
       48 
45 
     | 
    
         
             
                protected
         
     | 
| 
       49 
46 
     | 
    
         | 
| 
       50 
47 
     | 
    
         
             
                  def execute
         
     | 
| 
       51 
     | 
    
         
            -
                    self.class.operations.inject(input) do |data,  
     | 
| 
       52 
     | 
    
         
            -
                      operation 
     | 
| 
       53 
     | 
    
         
            -
                      operation = operation.new(data, options)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    self.class.operations.inject(input) do |data, operation|
         
     | 
| 
      
 49 
     | 
    
         
            +
                      operation = operation.create(self, data)
         
     | 
| 
       54 
50 
     | 
    
         
             
                      operation.perform
         
     | 
| 
       55 
51 
     | 
    
         | 
| 
       56 
52 
     | 
    
         
             
                      if operation.failed?
         
     | 
| 
         @@ -72,8 +72,10 @@ describe ComposableOperations::ComposedOperation do 
     | 
|
| 
       72 
72 
     | 
    
         
             
                  string_multiplier = self.string_multiplier
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
       74 
74 
     | 
    
         
             
                  Class.new(described_class) do
         
     | 
| 
      
 75 
     | 
    
         
            +
                    property :multiplicator, default: 3
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
       75 
77 
     | 
    
         
             
                    use string_generator
         
     | 
| 
       76 
     | 
    
         
            -
                    use string_multiplier, separator: ' - ', multiplicator:  
     | 
| 
      
 78 
     | 
    
         
            +
                    use string_multiplier, separator: ' - ', multiplicator: lambda { multiplicator }
         
     | 
| 
       77 
79 
     | 
    
         
             
                  end.new
         
     | 
| 
       78 
80 
     | 
    
         
             
                end
         
     | 
| 
       79 
81 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: composable_operations
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Konstantin Tennhard
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2013-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-06-16 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: smart_properties
         
     |