Class: BoPeep::Host::Callbacks::Definition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callbacks = nil, &setup) ⇒ Definition

Returns a new instance of Definition.



971
972
973
974
975
976
977
978
979
980
981
982
983
984
# File 'lib/bopeep.rb', line 971

def initialize(callbacks = nil, &setup)
  if callbacks
    @callbacks = Proxy.new(callbacks)
  else
    @callbacks = Callbacks.new
  end

  case setup&.arity
  when 1
    setup.call(self)
  when 0
    instance_eval(&setup)
  end
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



969
970
971
# File 'lib/bopeep.rb', line 969

def callbacks
  @callbacks
end

Instance Method Details

#on_failure(&block) ⇒ Object



998
999
1000
# File 'lib/bopeep.rb', line 998

def on_failure(&block)
  @callbacks.singleton_class.define_method(:on_failure, &block)
end

#on_stderr(&block) ⇒ Object



990
991
992
# File 'lib/bopeep.rb', line 990

def on_stderr(&block)
  @callbacks.singleton_class.define_method(:on_stderr, &block)
end

#on_stdout(&block) ⇒ Object



986
987
988
# File 'lib/bopeep.rb', line 986

def on_stdout(&block)
  @callbacks.singleton_class.define_method(:on_stdout, &block)
end

#on_success(&block) ⇒ Object



994
995
996
# File 'lib/bopeep.rb', line 994

def on_success(&block)
  @callbacks.singleton_class.define_method(:on_success, &block)
end