command_processor 0.1.4 → 0.1.5
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/command_processor/command.rb +1 -1
- data/lib/command_processor/extensions/loggable_processor.rb +19 -0
- data/lib/command_processor/extensions/transaction_processor.rb +14 -0
- data/lib/command_processor/processor.rb +1 -17
- data/lib/command_processor/version.rb +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1574d11130f50ce4f3fe692ccb18543329c7dba2
         | 
| 4 | 
            +
              data.tar.gz: 6fb1e33a4c8eb85746fa6f36d0142254a287a2ee
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e36370401f012893411065ea1d75a04a5d6c5d8cc089cb7472bbf5fc6e7edc0c5b01126c1408768ddb343f23639861331b6359ba22c42df7ad725e1c66738bd5
         | 
| 7 | 
            +
              data.tar.gz: f40e2caa979254dc2dd411f86231e36921ae3ac3c1988c7e4f41805c27fb314978544275a88df8d22cc1203eb7980566b64e72e83556fec7858987593c72583e
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module CommandProcessor
         | 
| 2 | 
            +
              class LoggableProcessor
         | 
| 3 | 
            +
                def initialize(processor, logger, blacklisted_parameters=[])
         | 
| 4 | 
            +
                  @processor = processor
         | 
| 5 | 
            +
                  @logger = logger
         | 
| 6 | 
            +
                  @blacklisted_parameters = blacklisted_parameters
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def execute(command)
         | 
| 10 | 
            +
                  parameters = command.to_params
         | 
| 11 | 
            +
                  filtered_parameters = parameters.inject({}) do |memo, (key, value)|
         | 
| 12 | 
            +
                    filtered_value = @blacklisted_parameters.include?(key) ? "[FILTERED]" : value
         | 
| 13 | 
            +
                    memo.merge(key => filtered_value)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                  @logger.info("Processing #{command.class.name}\n  Parameters: #{filtered_parameters}")
         | 
| 16 | 
            +
                  @processor.execute(command)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module CommandProcessor
         | 
| 2 | 
            +
              class TransactionProcessor
         | 
| 3 | 
            +
                def initialize(processor, database)
         | 
| 4 | 
            +
                  @processor = processor
         | 
| 5 | 
            +
                  @database = database
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def execute(command)
         | 
| 9 | 
            +
                  @database.transaction do
         | 
| 10 | 
            +
                    @processor.execute(command)
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -1,13 +1,9 @@ | |
| 1 1 | 
             
            require "command_processor/container"
         | 
| 2 | 
            -
            require "command_processor/exceptions"
         | 
| 3 | 
            -
            require "logger"
         | 
| 4 2 |  | 
| 5 3 | 
             
            module CommandProcessor
         | 
| 6 4 | 
             
              class Processor
         | 
| 7 | 
            -
                def initialize | 
| 5 | 
            +
                def initialize
         | 
| 8 6 | 
             
                  @container = Container.new
         | 
| 9 | 
            -
                  @logger = logger
         | 
| 10 | 
            -
                  @blacklisted_parameters = blacklisted_parameters
         | 
| 11 7 | 
             
                end
         | 
| 12 8 |  | 
| 13 9 | 
             
                def register(*args, &block)
         | 
| @@ -17,18 +13,6 @@ module CommandProcessor | |
| 17 13 | 
             
                def execute(command)
         | 
| 18 14 | 
             
                  handler_class = Object.const_get("#{command.class.name}Handler")
         | 
| 19 15 | 
             
                  handler = @container.resolve_by_type(handler_class)
         | 
| 20 | 
            -
                  
         | 
| 21 | 
            -
                  #log
         | 
| 22 | 
            -
                  parameters = command.to_h
         | 
| 23 | 
            -
                  filtered_parameters = parameters.inject({}) do |memo, (key, value)|
         | 
| 24 | 
            -
                    if @blacklisted_parameters.include?(key.to_s)
         | 
| 25 | 
            -
                      memo.merge(key => "[FILTERED]")
         | 
| 26 | 
            -
                    else
         | 
| 27 | 
            -
                      memo.merge(key => value)
         | 
| 28 | 
            -
                    end
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
                  @logger.info("Processed by #{handler.class.name}\n  Parameters: #{filtered_parameters}")
         | 
| 31 | 
            -
             | 
| 32 16 | 
             
                  handler.execute(command)
         | 
| 33 17 | 
             
                end
         | 
| 34 18 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: command_processor
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Erik Lott
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-09-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: ioc
         | 
| @@ -85,6 +85,8 @@ files: | |
| 85 85 | 
             
            - lib/command_processor/command.rb
         | 
| 86 86 | 
             
            - lib/command_processor/container.rb
         | 
| 87 87 | 
             
            - lib/command_processor/exceptions.rb
         | 
| 88 | 
            +
            - lib/command_processor/extensions/loggable_processor.rb
         | 
| 89 | 
            +
            - lib/command_processor/extensions/transaction_processor.rb
         | 
| 88 90 | 
             
            - lib/command_processor/handler.rb
         | 
| 89 91 | 
             
            - lib/command_processor/processor.rb
         | 
| 90 92 | 
             
            - lib/command_processor/version.rb
         |