Class: Upmin::Parameter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, parameter_name, options = {}) ⇒ Parameter

Returns a new instance of Parameter.



6
7
8
9
10
# File 'lib/upmin/parameter.rb', line 6

def initialize(action, parameter_name, options = {})
  @action = action
  @name = parameter_name.to_sym
  @type = options[:type] if options[:type]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/upmin/parameter.rb', line 3

def action
  @action
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/upmin/parameter.rb', line 4

def name
  @name
end

Instance Method Details

#form_idObject



32
33
34
# File 'lib/upmin/parameter.rb', line 32

def form_id
  return "#{action.name}_#{name}"
end

#label_nameObject



20
21
22
# File 'lib/upmin/parameter.rb', line 20

def label_name
  name.to_s.capitalize.gsub("_", " ")
end

#modelObject



12
13
14
# File 'lib/upmin/parameter.rb', line 12

def model
  return action.model
end

#nil_form_idObject



36
37
38
# File 'lib/upmin/parameter.rb', line 36

def nil_form_id
  return "#{form_id}_is_nil"
end

#titleObject



16
17
18
# File 'lib/upmin/parameter.rb', line 16

def title
  return name.to_s.humanize
end

#typeObject



24
25
26
27
28
29
30
# File 'lib/upmin/parameter.rb', line 24

def type
  return @type if defined?(@type)
  @type = action.model.method(action.name).parameters.select do |param_type, param_name|
    param_name == name
  end.first.first || :req
  return @type
end