Class: QueenCheck::Core::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/queencheck/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, method, args) ⇒ Task

Returns a new instance of Task.



72
73
74
75
76
77
78
79
# File 'lib/queencheck/core.rb', line 72

def initialize(instance, method, args)
  @is_pass = nil
  @instance = instance
  @method = method
  @arguments = args
  @result = nil
  @exception = nil
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def arguments
  @arguments
end

#exceptionObject (readonly)

Returns the value of attribute exception.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def exception
  @exception
end

#instanceObject (readonly)

Returns the value of attribute instance.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def instance
  @instance
end

#is_passObject (readonly)

Returns the value of attribute is_pass.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def is_pass
  @is_pass
end

#methodObject (readonly)

Returns the value of attribute method.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def method
  @method
end

#resultObject (readonly)

Returns the value of attribute result.



80
81
82
# File 'lib/queencheck/core.rb', line 80

def result
  @result
end

Instance Method Details

#run!(&check_block) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/queencheck/core.rb', line 82

def run!(&check_block)
  return unless @is_pass.nil?
  func = @method.respond_to?(:call) ? @method : @instance.method(@method)

  begin
    @result = func.call(*@arguments)
  rescue Exception => e
    @exception = e
  end

  @is_pass = !!check_block.call(@result, @arguments, @exception) if check_block

  return self
end

#to_s(verbose = false) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/queencheck/core.rb', line 97

def to_s(verbose = false)
  if verbose
    "<#{@instance.class.name}:#{@instance.object_id}>\##{@method.kind_of?(Method) ? @method.name : '::lambda::'}(" +
    @arguments.map { |arg| "#{arg.class.name}:#{arg}" }.join(', ') +
    ") => <#{@result.class.name}:#{@result}>" +
    (!@is_pass ? " !! #{@exception.class.name}: #{@exception.message}" : '')
  else
    "#{@instance.class.name}\##{@method.respond_to?(:call) ? '::lambda::' : @method}(" +
    @arguments.map {|arg| "#{arg}" } .join(', ') +
    ") => #{@result}" + (!@is_pass ? "! #{@exception.class.name}: #{@exception.message}": '')
  end
end