Class: SuperAuth::ActiveRecord::Authorization

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/super_auth/active_record/authorization.rb

Class Method Summary collapse

Class Method Details

.compile!Object

Clears and repopulates the authorizations table from the current graph with one INSERT ... SELECT on this connection, and returns the row count; see SuperAuth::Authorization.compile!. The guards run before the delete, so a refused compile leaves the previous rows in place.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/super_auth/active_record/authorization.rb', line 15

def compile!
  transaction do
    # Sequel runs on this transaction's connection (sequel-activerecord_connection),
    # so the JIT switch lands in it; see SuperAuth::Authorization.compile!.
    SuperAuth.db.run "SET LOCAL jit = off" if SuperAuth.db.database_type == :postgres
    SuperAuth::Authorization.assert_compilable!
    delete_all
    connection.execute(
      SuperAuth.db[:super_auth_authorizations].insert_sql(
        SuperAuth::Edge::AUTHORIZATION_COLUMNS, SuperAuth::Authorization.compile_source
      )
    )
    count
  end
end

.from_graphObject

Returns all computed authorization paths as Authorization AR objects. These can be saved directly to the super_auth_authorizations table.



7
8
9
# File 'lib/super_auth/active_record/authorization.rb', line 7

def from_graph
  from("(#{SuperAuth::Edge.authorizations.sql}) as super_auth_authorizations".squish)
end