Sha256: 49dc6e68cfdb4c6c5cc8fc8a32b89bd8a772ac3463ecfc286e008ba86945387c

Contents?: true

Size: 874 Bytes

Versions: 3

Compression:

Stored size: 874 Bytes

Contents

# Converts {'model[attribute]' => value} into {'model' => {'attribute' => value}}
module Crystal
  module Processors
    class ScopedParams < Processor      
      def call
        if workspace.params?
          to_delete = []
          workspace.params.each do |name, value|
            name.scan /(.+)\[(.+)\]/ do |scope_name, name_in_scope|
              scope = workspace.params[scope_name] ||= {}
            
              unless scope.is_a? Hash
                logger.warn "Owerriding :#{scope} param!"
                scope = {}
                workspace.params[scope_name] = scope
              end
            
              scope[name_in_scope] = value
              to_delete << name
            end
          end
          to_delete.each{|n| workspace.params.delete n}
        end
                
        next_processor.call
      end
    end
  end
end
      

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
crystal-0.0.13 lib/crystal/html/processors/scoped_params.rb
crystal-0.0.12 lib/crystal/html/processors/scoped_params.rb
crystal_ext-0.0.11 lib/crystal/html/processors/scoped_params.rb