Module: Reaction::HasParams

Included in:
Action
Defined in:
lib/reaction/has_params.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/reaction/has_params.rb', line 3

def self.included(base)
  base.include HasDocs
  base.include HasMetas
  base.include HasTypes
  base.include HasValidators
  base.extend ClassMethods
end

Instance Method Details

#param(name) ⇒ Object



18
19
20
21
22
23
# File 'lib/reaction/has_params.rb', line 18

def param(name)
  typed_params[name.to_sym] ||= begin
    type = self.class.types[name.to_sym]
    type ? type.convert(raw_param(name)) : raw_param(name)
  end
end

#paramsObject



25
26
27
# File 'lib/reaction/has_params.rb', line 25

def params
  @params ||= {}
end

#raw_param(name) ⇒ Object



44
45
46
# File 'lib/reaction/has_params.rb', line 44

def raw_param(name)
  params[name.to_sym]
end

#set_param(name, value, meta = {}) ⇒ Object



33
34
35
36
# File 'lib/reaction/has_params.rb', line 33

def set_param(name, value, meta = {})
  set_meta(name, meta)
  params[name.to_sym] = value
end

#set_params(params = {}, meta = {}) ⇒ Object



38
39
40
41
42
# File 'lib/reaction/has_params.rb', line 38

def set_params(params = {}, meta = {})
  params.each do |name, value|
    set_param(name, value, meta)
  end
end

#typed_paramsObject



29
30
31
# File 'lib/reaction/has_params.rb', line 29

def typed_params
  @typed_params ||= {}
end