Class: Sequel::ConnectionGuard::Executor Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/extensions/connection_guard/executor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides a DSL for accessing the database safely.

Examples:

Safely accessing a database

DB.safe_execute do
  alive do |db|
    db[:users].all
  end

  dead do
    []
  end
end

Safely accessing a model

UserGuard.safe_execute do
  alive do |model|
    model.first!
  end

  # `dead` handler is optional
end

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_deadObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



32
33
34
# File 'lib/sequel/extensions/connection_guard/executor.rb', line 32

def on_dead
  @on_dead
end

Instance Method Details

#alive(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • block (Proc)

Since:

  • 0.1.0



38
39
40
# File 'lib/sequel/extensions/connection_guard/executor.rb', line 38

def alive(&block)
  @on_alive = block
end

#dead(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • block (Proc)

Since:

  • 0.1.0



46
47
48
# File 'lib/sequel/extensions/connection_guard/executor.rb', line 46

def dead(&block)
  @on_dead = block
end

#on_aliveObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

Since:

  • 0.1.0



54
55
56
57
# File 'lib/sequel/extensions/connection_guard/executor.rb', line 54

def on_alive
  raise ConfigurationError, "`alive` handler is required for .safe_execute" if @on_alive.nil?
  @on_alive
end