Class: ScopedParams

Inherits:
Rad::Conveyors::Processor show all
Defined in:
lib/rad/html/processors/scoped_params.rb

Overview

Converts href="attribute">model’ => value into => {‘attribute’ => value}

Instance Attribute Summary

Attributes inherited from Rad::Conveyors::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Rad::Conveyors::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Rad::Conveyors::Processor

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rad/html/processors/scoped_params.rb', line 5

def call
  if workspace.params?
    to_delete = []
    to_add = {}
    workspace.params.each do |name, value|
      name.to_s.scan /(.+)\[(.+)\]/ do |scope_name, name_in_scope|
        logger.warn "RAD owerriding :#{scope} param!" if workspace.params.include? scope_name
        scope = to_add[scope_name.to_sym] ||= {}
        scope[name_in_scope] = value
        to_delete << name
      end
    end
    workspace.params.merge! to_add
    to_delete.each{|n| workspace.params.delete n}
  end

  next_processor.call
end