Class: Ink::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/webinkforms.rb

Instance Method Summary collapse

Instance Method Details

#params(method) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/webinkforms.rb', line 3

def params(method)
  return if @params[method].nil? or @params[method].empty?
  objects = {:params => {}, :refs => {}, :others => {}}
  @params[method].keys.each do |k|
    if k =~ /^#{prefix_submit}(.*)$/
      name = $1
      objects[:submit] = Ink::Model.from_refstr(name) || name
      objects[:submit_value] = @params[method][k]
    elsif k =~ /^#{prefix_set}(.*)$/
      name = $1
      obj = nil
      if @params[method][k].is_a? Array
        obj = @params[method][k].map{|i| Ink::Model.from_refstr(i) || i}
      else
        obj = Ink::Model.from_refstr(@params[method][k]) ||
          @params[method][k]
      end
      objects[:params][name] = obj
    elsif k =~ /^#{prefix_ref}(.*)$/
      name = $1
      obj = nil
      if @params[method][k].is_a? Array
        obj = @params[method][k].map{|i| Ink::Model.from_refstr(i) || i}
      else
        obj = Ink::Model.from_refstr(@params[method][k]) ||
          @params[method][k]
      end
      ref = Ink::Model.from_refstr(name) || name
      objects[:refs][ref] = obj
    else
      objects[:others][k] = @params[method][k]
    end
  end

  if block_given?
    yield(objects)
    nil
  else
    objects
  end
end

#prefix_refObject



49
50
51
# File 'lib/webinkforms.rb', line 49

def prefix_ref
  "ref_"
end

#prefix_setObject



53
54
55
# File 'lib/webinkforms.rb', line 53

def prefix_set
  "set_"
end

#prefix_submitObject



45
46
47
# File 'lib/webinkforms.rb', line 45

def prefix_submit
  "submit_"
end