Module: Params

Included in:
Rambo::Controller
Defined in:
lib/rambo/controller/params.rb

Instance Method Summary collapse

Instance Method Details

#indifferent_hashObject



23
24
25
# File 'lib/rambo/controller/params.rb', line 23

def indifferent_hash
  Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
end

#paramsObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rambo/controller/params.rb', line 2

def params
  if !self.request.params.keys.join.include?('[')
    @params ||= indifferent_hash.merge(self.request.params)
  else
    @params ||= self.request.params.inject indifferent_hash do |res, (key,val)|
      if key.include?('[')
        head = key.split(/[\]\[]+/)
        last = head.pop
        head.inject(res){ |hash,k| hash[k] ||= indifferent_hash }[last] = val
      else
        res[key] = val
      end
      res
    end
  end
  if request.path_components.size() > 2
    @params.merge!(:id => request.path_components[3])
  end
  @params
end