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, name, settings = {}) ⇒ Role

Returns a new instance of Role.

Parameters:

  • connection (ActiveRecord::ConnectionAdapters::AbstractAdapter) —

    the one to switch.

  • name (String) —

    the role to enter.

  • settings (Hash) (defaults to: {}) —

    what to set first, which a row policy may read to scope the rows.



13
14
15
16
17
# File 'app/models/omen/role.rb', line 13

def initialize(connection, name, settings = {})
  @connection = connection
  @name = name
  @settings = settings
end

Instance Method Details

#around ⇒ Object

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

Returns:

  • (Object) —

    whatever the block answered.



21
22
23
24
# File 'app/models/omen/role.rb', line 21

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