Class: NeuronCheckSystem::CondBlockContext

Inherits:
Object
  • Object
show all
Defined in:
lib/neuroncheck/cond_block.rb

Instance Method Summary collapse

Constructor Details

#initialize(block_name, method_self, allow_instance_method) ⇒ CondBlockContext

Returns a new instance of CondBlockContext.



3
4
5
6
7
# File 'lib/neuroncheck/cond_block.rb', line 3

def initialize(block_name, method_self, allow_instance_method)
  @block_name = block_name
  @method_self = method_self
  @allow_instance_method = allow_instance_method
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/neuroncheck/cond_block.rb', line 9

def method_missing(name, *args, &block)
  if @method_self.respond_to?(name, true) then
    if @allow_instance_method then
      @method_self.send(name, *args, &block)
    else
      raise NeuronCheckSystem::DeclarationError, "instance method `#{name}' cannot be called in #{@block_name}, it is forbidden", (NeuronCheck.debug? ? caller : caller(1))
    end
  else
    super
  end
end

Instance Method Details

#assert(*dummy) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/neuroncheck/cond_block.rb', line 21

def assert(*dummy)
  unless block_given? then
    raise NeuronCheckSystem::DeclarationError, "no block given for `assert' in #{@block_name}", (NeuronCheck.debug? ? caller : caller(1))
  end

  passed = yield

  unless passed
    locs = Utils.backtrace_locations_to_captions(caller(1, 1))

    msg = <<MSG
#{@block_name} assertion failed
  asserted at: #{locs.join("\n" + ' ' * 15)}

MSG

    # エラーを発生させる
    throw :neuron_check_error_tag, msg
  end
end