Class: Omen::Role

Inherits:
Object
  • Object
show all
Defined in:
app/models/omen/role.rb

Overview

The Postgres role a reading's statement runs as, which is refused the reading's own tables.

Defined Under Namespace

Classes: Unavailable

Constant Summary collapse

MISCONFIGURED =

Ours to write, since it quotes no row: what an asker is told when it was the setup that failed.

'This app is misconfigured, not the question -- ask an engineer to install ' \
'the read-only role a statement runs as.'

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Role

Returns a new instance of Role.

Parameters:

  • connection (ActiveRecord::ConnectionAdapters::AbstractAdapter)

    the one to switch.



11
12
13
# File 'app/models/omen/role.rb', line 11

def initialize(connection)
  @connection = connection
end

Instance Method Details

#aroundObject

Given up before anything of ours runs; a statement Postgres refused rolls it back instead.

Returns:

  • (Object)

    whatever the block answered.



17
18
19
20
# File 'app/models/omen/role.rb', line 17

def around
  enter
  yield.tap { @connection.execute 'SET LOCAL ROLE NONE' }
end