Module: CrazyTrain

Defined in:
lib/crazy_train.rb,
lib/crazy_train/jwt.rb,
lib/crazy_train/grant.rb,
lib/crazy_train/engine.rb,
lib/crazy_train/railtie.rb,
lib/crazy_train/version.rb,
app/models/crazy_train/table.rb,
app/models/crazy_train/order_parser.rb,
app/jobs/crazy_train/application_job.rb,
app/models/crazy_train/query_builder.rb,
app/models/crazy_train/application_record.rb,
app/helpers/crazy_train/application_helper.rb,
app/mailers/crazy_train/application_mailer.rb,
app/controllers/crazy_train/tables_controller.rb,
app/controllers/crazy_train/resources_controller.rb,
app/controllers/crazy_train/application_controller.rb,
lib/generators/crazy_train/install/install_generator.rb

Defined Under Namespace

Modules: ApplicationHelper, Generators Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Config, Engine, Grant, JWT, OrderParser, QueryBuilder, Railtie, ResourcesController, Table, TablesController

Constant Summary collapse

VERSION =
'0.2.0'.freeze
@@config =
Config.new(
  secret: 'you-must-change-this',
  unauthorized_role: 'anonymous',
  authenticated_role: 'authenticated'
)

Class Method Summary collapse

Class Method Details

.configObject



14
15
16
# File 'lib/crazy_train.rb', line 14

def self.config
  @@config
end

.current_roleObject



22
23
24
# File 'lib/crazy_train.rb', line 22

def self.current_role
  ActiveRecord::Base.connection.execute('SELECT current_user').to_a.first['current_user']
end

.current_settingsObject



26
27
28
# File 'lib/crazy_train.rb', line 26

def self.current_settings
  ActiveRecord::Base.connection.execute('SELECT current_setting').to_a.first['current_setting']
end

.request_jwt_claimsObject



34
35
36
37
38
# File 'lib/crazy_train.rb', line 34

def self.request_jwt_claims
  sql = "SELECT current_setting('request.jwt.claims', true) AS request_jwt_claims"
  string = ActiveRecord::Base.connection.execute(sql).to_a.first['request_jwt_claims']
  JSON.parse(string)
end

.setup {|@@config| ... } ⇒ Object

Yields:



18
19
20
# File 'lib/crazy_train.rb', line 18

def self.setup
  yield @@config
end

.setup_jwt_claims!(paylaod) ⇒ Object



30
31
32
# File 'lib/crazy_train.rb', line 30

def self.setup_jwt_claims!(paylaod)
  ActiveRecord::Base.connection.execute("SET request.jwt.claims = '#{paylaod}'")
end