Class: Reaction::Param

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, type, validators, name, raw_value, provided = true) ⇒ Param

Returns a new instance of Param.



13
14
15
16
17
18
19
20
# File 'lib/reaction/param.rb', line 13

def initialize(action, type, validators, name, raw_value, provided = true)
  @action = action
  @type = type
  @validators = validators
  @name = name
  @raw_value = raw_value
  @provided = provided
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



3
4
5
# File 'lib/reaction/param.rb', line 3

def action
  @action
end

#errorObject

Returns the value of attribute error.



11
12
13
# File 'lib/reaction/param.rb', line 11

def error
  @error
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/reaction/param.rb', line 6

def name
  @name
end

#raw_valueObject

Returns the value of attribute raw_value.



7
8
9
# File 'lib/reaction/param.rb', line 7

def raw_value
  @raw_value
end

#resultObject

Returns the value of attribute result.



10
11
12
# File 'lib/reaction/param.rb', line 10

def result
  @result
end

#successfulObject

Returns the value of attribute successful.



9
10
11
# File 'lib/reaction/param.rb', line 9

def successful
  @successful
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/reaction/param.rb', line 4

def type
  @type
end

#validatorsObject

Returns the value of attribute validators.



5
6
7
# File 'lib/reaction/param.rb', line 5

def validators
  @validators
end

Instance Method Details

#failure(error) ⇒ Object



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

def failure(error)
  @error = ParamError.new(name, error)
  @successful = false
end

#processObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/reaction/param.rb', line 22

def process
  if type.process(raw_value)
    validators.each do |validator|
      unless validator.process(type.result)
        failure(validator.error)
        return false
      end
    end
  else
    failure(type.error)
    return false
  end
  success(type.result)
  true
end

#provided?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/reaction/param.rb', line 48

def provided?
  !!@provided
end

#success(result) ⇒ Object



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

def success(result)
  @result = result
  @successful = true
end