Class: QueenCheck::Core::Task
- Inherits:
-
Object
- Object
- QueenCheck::Core::Task
- Defined in:
- lib/queencheck/core.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#is_pass ⇒ Object
readonly
Returns the value of attribute is_pass.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(instance, method, args) ⇒ Task
constructor
A new instance of Task.
- #run!(&check_block) ⇒ Object
- #to_s(verbose = false) ⇒ Object
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
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
80 81 82 |
# File 'lib/queencheck/core.rb', line 80 def arguments @arguments end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
80 81 82 |
# File 'lib/queencheck/core.rb', line 80 def exception @exception end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
80 81 82 |
# File 'lib/queencheck/core.rb', line 80 def instance @instance end |
#is_pass ⇒ Object (readonly)
Returns the value of attribute is_pass.
80 81 82 |
# File 'lib/queencheck/core.rb', line 80 def is_pass @is_pass end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
80 81 82 |
# File 'lib/queencheck/core.rb', line 80 def method @method end |
#result ⇒ Object (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.}" : '') else "#{@instance.class.name}\##{@method.respond_to?(:call) ? '::lambda::' : @method}(" + @arguments.map {|arg| "#{arg}" } .join(', ') + ") => #{@result}" + (!@is_pass ? "! #{@exception.class.name}: #{@exception.}": '') end end |