Module: Omen

Defined in:
lib/omen.rb,
lib/omen/bound.rb,
lib/omen/config.rb,
lib/omen/engine.rb,
lib/omen/grants.rb,
lib/omen/renamed.rb,
lib/omen/version.rb,
lib/omen/distance.rb,
lib/omen/inquirer.rb,
lib/omen/narrowing.rb,
lib/omen/time_zone.rb,
lib/omen/attributes.rb,
lib/omen/requirements.rb,
lib/generators/omen/pages/pages_generator.rb,
lib/generators/omen/install/install_generator.rb

Overview

Staff ask Claude a question about the data an app holds; Claude writes the SQL, Rails runs it.

Defined Under Namespace

Modules: Asked, Attributes, Bound, Distance, Executed, Generators, Grants, Inquirer, Narrowed, Renamed, Requirements, Revealed, Spoken, Stated, Stubs, TimeZone Classes: Answer, Column, Combination, Config, Conversation, Engine, Instructions, Narrowing, Query, Question, Reading, Refusal, Reply, Role, Schema

Constant Summary collapse

REFUSED =

Said where a database refuses one group, since the groups need nothing from one another.

'Skipped, refused by the database: %{statement} (%{error})'
VERSION =

The version of this gem, as RubyGems knows it.

'0.9.0'

Class Method Summary collapse

Class Method Details

.attempted(connection, *statements) ⇒ void

This method returns an undefined value.

A savepoint each and a warning rather than a raise, so a statement a managed database refuses discards neither the deploy nor the statements behind it -- and what arrives together is applied together, since a table is never left with row level security on and no policy under it.

Parameters:

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

    a writing one.

  • statements (Array<String>) —

    what to run, all of it or none of it.



43
44
45
46
47
48
49
# File 'lib/omen.rb', line 43

def self.attempted(connection, *statements)
  connection.transaction(requires_new: true) do
    statements.each { |statement| connection.execute statement }
  end
rescue ActiveRecord::StatementInvalid => error
  warn REFUSED % { statement: statements.first.squish, error: error.message.lines.first.strip }
end

.config ⇒ Omen::Config

Returns everything this feature has to be told about the app around it.

Returns:

  • (Omen::Config) —

    everything this feature has to be told about the app around it.



24
# File 'lib/omen.rb', line 24

def self.config = @config ||= Omen::Config.new

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Yields the configuration, so a host states its own facts in one initializer.

Yields:



28
# File 'lib/omen.rb', line 28

def self.configure = yield config

.each_database {|ActiveRecord::ConnectionAdapters::AbstractAdapter| ... } ⇒ void

This method returns an undefined value.

Yields:

  • (ActiveRecord::ConnectionAdapters::AbstractAdapter) —

    a writing connection to each database this environment prepares.



54
55
56
57
58
59
60
61
# File 'lib/omen.rb', line 54

def self.each_database
  environments.each do |environment|
    config = ActiveRecord::Base.configurations.configs_for env_name: environment,
      name: 'primary'
    next unless config
    ActiveRecord::Tasks::DatabaseTasks.with_temporary_connection(config) { |it| yield it }
  end
end

.environments ⇒ Array<String>

Returns the environments whose databases a grant should cover.

Returns:

  • (Array<String>) —

    the environments whose databases a grant should cover.



34
# File 'lib/omen.rb', line 34

def self.environments = Rails.env.development? ? %w[ development test ] : [Rails.env.to_s]

.tables ⇒ Array<String>

Hidden twice over: out of the prompt, and out of what the statement's own role may read.

Returns:

  • (Array<String>) —

    the tables this feature keeps its log of questions and answers in.



21
# File 'lib/omen.rb', line 21

def self.tables = [ Omen::Reading, Omen::Question, Omen::Answer ].map(&:table_name)