Class: Lavin::Hook
- Inherits:
-
Object
- Object
- Lavin::Hook
- Defined in:
- lib/lavin/hook.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #call(context:) ⇒ Object
-
#initialize(user:, type: :before, &block) ⇒ Hook
constructor
A new instance of Hook.
- #run(context: nil) ⇒ Object
Constructor Details
#initialize(user:, type: :before, &block) ⇒ Hook
Returns a new instance of Hook.
9 10 11 12 13 |
# File 'lib/lavin/hook.rb', line 9 def initialize(user:, type: :before, &block) @user = user @block = block @type = type end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/lavin/hook.rb', line 7 def block @block end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/lavin/hook.rb', line 7 def type @type end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'lib/lavin/hook.rb', line 7 def user @user end |
Instance Method Details
#call(context:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lavin/hook.rb', line 20 def call(context:) report_statistics = context.client.report_statistics context.client.report_statistics = false context.instance_exec(&block) rescue SuccessfulStep, RecoverableError rescue SuccessfulUser, IrrecoverableError throw :stop_user rescue => error puts "Exception in #{user.name}.#{type} block - #{error.class}: #{error.}" ensure context.client.report_statistics = report_statistics end |