Skip to content

Commit

Permalink
Convert JSON strings to symbols and classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
maedi committed Oct 3, 2020
1 parent edcd0c9 commit 35cff6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions lib/Reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(execution, method, ruler)
# Result.
@status = nil
@time = Time.now.to_i
@input = []
@inputs = []
@output = nil

end
Expand All @@ -49,24 +49,24 @@ def reflect(*args)
args.each do |arg|
case arg
when Integer
@input << rand(999)
@inputs << rand(999)
else
@input << arg
@inputs << arg
end
end

# Action method with new arguments.
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
Expand All @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions lib/Ruler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Ruler
def initialize()

@controls = nil

# Rules.
@inputs = []
@output = nil

Expand All @@ -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?
Expand All @@ -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])
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions lib/reflekt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35cff6d

Please sign in to comment.