diff --git a/lib/Reflection.rb b/lib/Reflection.rb index 3df3566..0202358 100644 --- a/lib/Reflection.rb +++ b/lib/Reflection.rb @@ -28,7 +28,7 @@ def initialize(execution, method, ruler) # Result. @status = nil @time = Time.now.to_i - @input = [] + @inputs = [] @output = nil end @@ -49,9 +49,9 @@ def reflect(*args) args.each do |arg| case arg when Integer - @input << rand(999) + @inputs << rand(999) else - @input << arg + @inputs << arg end end @@ -59,14 +59,14 @@ def reflect(*args) begin # Validate input with controls. unless @ruler.nil? - if @ruler.validate_input(@execution.caller_class, @method, @input) + if @ruler.validate_inputs(@execution.caller_class, @method, @inputs) @status = PASS else @status = FAIL end end # Run reflection. - @output = @clone.send(@method, *@input) + @output = @clone.send(@method, *@inputs) # When fail. rescue StandardError => message @status = FAIL @@ -92,7 +92,7 @@ def result() reflection = { TIME => @time, STATUS => @status, - INPUT => normalize_input(@input), + INPUT => normalize_input(@inputs), OUTPUT => normalize_output(@output), MESSAGE => @message } diff --git a/lib/Ruler.rb b/lib/Ruler.rb index 238e421..b083668 100644 --- a/lib/Ruler.rb +++ b/lib/Ruler.rb @@ -10,6 +10,8 @@ class Ruler def initialize() @controls = nil + + # Rules. @inputs = [] @output = nil @@ -20,10 +22,6 @@ def load(controls) @controls = controls @controls.each_with_index do |control, index| - p '-----' - p control - p '-----' - # Multiple inputs. control[INPUT].each_with_index do |input, index| unless input.nil? @@ -38,7 +36,7 @@ def load(controls) # Add rules to rule. unless input[TYPE].nil? || input[TYPE].empty? - rule.add_type(input[TYPE]) + rule.add_type(input[TYPE].class) end unless input[VALUE].nil? || input[VALUE].empty? rule.add_value(input[VALUE]) @@ -89,7 +87,7 @@ def train() end - def validate_input(klass, method, inputs) + def validate_inputs(klass, method, inputs) result = true inputs.each_with_index do |value, index| rule = @inputs[index] diff --git a/lib/reflekt.rb b/lib/reflekt.rb index 283336e..0f1355e 100644 --- a/lib/reflekt.rb +++ b/lib/reflekt.rb @@ -63,8 +63,8 @@ def initialize(*args) # Get ruler. # The method's ruler will not exist the first time the db generated. - if @@reflekt_rules.key? execution.caller_class - ruler = @@reflekt_rules[execution.caller_class][method_name] + if @@reflekt_rules.key? execution.caller_class.to_s.to_sym + ruler = @@reflekt_rules[execution.caller_class.to_s.to_sym][method.to_s] else ruler = nil end