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



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

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

#paramsObject



29
30
31
32
33
34
35
# File 'lib/reaction/has_params.rb', line 29

def params
  ret = {}
  raw_params.keys.each do |name|
    ret[name.to_sym] = param(name)
  end
  ret
end

#raw_param(name) ⇒ Object



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

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

#raw_paramsObject



57
58
59
# File 'lib/reaction/has_params.rb', line 57

def raw_params
  @raw_params ||= {}
end

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



41
42
43
44
45
# File 'lib/reaction/has_params.rb', line 41

def set_param(name, value, meta = {})
  return unless self.class.param_settable?(name)
  set_meta(name, meta)
  raw_params[name.to_sym] = value
end

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



47
48
49
50
51
# File 'lib/reaction/has_params.rb', line 47

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

#typed_paramsObject



37
38
39
# File 'lib/reaction/has_params.rb', line 37

def typed_params
  @typed_params ||= {}
end

#validate_paramsObject



61
62
63
64
65
66
67
68
69
# File 'lib/reaction/has_params.rb', line 61

def validate_params
  raw_params.each do |name, value|
    self.class.type(name).validate_each(self, name, value)
    converted = param(name)
    self.class.validators(name).each do |validator|
      validator.validate_each(self, name, converted)
    end
  end
end