Class: Checky::Checker

Inherits:
Object show all
Includes:
Validators::All
Defined in:
lib/checky/checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChecker

Returns a new instance of Checker.



8
9
10
11
# File 'lib/checky/checker.rb', line 8

def initialize
  @storage = OpenStruct.new(checky_blocks: {}, checky_results: {})
  @self_before_instance_eval = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

rubocop:disable Style/MethodMissing



28
29
30
31
32
33
34
# File 'lib/checky/checker.rb', line 28

def method_missing(method, *args, &block)
  raise Checky::Exception unless methods.include?("populate_#{method}".to_sym)
  @storage.send("#{method}=", send("populate_#{method}", *args, &block))
  @storage.checky_blocks[method.to_sym] = block if block_given?
rescue Checky::Exception
  @self_before_instance_eval.send method, *args, &block if @self_before_instance_eval.present?
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



6
7
8
# File 'lib/checky/checker.rb', line 6

def storage
  @storage
end

Instance Method Details

#check(&block) ⇒ Object



13
14
15
16
17
18
# File 'lib/checky/checker.rb', line 13

def check(&block)
  @self_before_instance_eval = eval 'self', block.binding
  instance_eval(&block)
  with_hooks { check_result }
  @storage.checky_final_result
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

:nocov: :reek:BooleanParameter

Returns:

  • (Boolean)


22
23
24
# File 'lib/checky/checker.rb', line 22

def respond_to_missing?(method, _include_private = false)
  methods.include?("run_#{method}".to_sym)
end