Module: Slimer

Defined in:
lib/slimer.rb,
lib/slimer/web.rb,
lib/slimer/api_key.rb,
lib/slimer/version.rb,
lib/slimer/database.rb,
lib/slimer/substance.rb,
lib/slimer/web/action.rb,
lib/slimer/web/router.rb,
lib/slimer/web/helpers.rb,
lib/slimer/web/application.rb,
lib/slimer/web/csfr_protection.rb,
lib/slimer/workers/ingest_substance.rb

Overview

Slimer

Defined Under Namespace

Modules: WebHelpers, WebRouter, Workers Classes: ApiKey, Database, Error, Substance, Web, WebAction, WebApplication, WebRoute

Constant Summary collapse

DEFAULT_GROUP =
"general"
DEFAULT_DATABASE_URL =
"sqlite://./slimer.db"
DEFAULT_SIDEKIQ_QUEUE =
"slimer"
DEFAULTS =
{
  groups: Set.new([DEFAULT_GROUP]),
  database_url: DEFAULT_DATABASE_URL,
  sidekiq_queue: DEFAULT_SIDEKIQ_QUEUE
}.freeze
VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Slimer)

    the object that the method was called on



78
79
80
# File 'lib/slimer.rb', line 78

def self.configure
  yield self
end

.configure_sidekiq_client(&block) ⇒ Object



82
83
84
# File 'lib/slimer.rb', line 82

def self.configure_sidekiq_client(&block)
  Sidekiq.configure_client(&block)
end

.configure_sidekiq_server(&block) ⇒ Object



86
87
88
# File 'lib/slimer.rb', line 86

def self.configure_sidekiq_server(&block)
  Sidekiq.configure_server(&block)
end

.database_url(db_url = nil) ⇒ Object



60
61
62
63
# File 'lib/slimer.rb', line 60

def self.database_url(db_url = nil)
  self.database_url = db_url if db_url
  options[:database_url]
end

.database_url=(db_url) ⇒ Object



65
66
67
# File 'lib/slimer.rb', line 65

def self.database_url=(db_url)
  @options[:database_url] = db_url
end

.dbObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/slimer.rb', line 32

def self.db
  database_url_from_env = ENV.delete("SLIMER_DATABASE_URL") || ENV.delete("DATABASE_URL")

  if database_url_from_env
    @options[:database_url] = database_url_from_env
    return @db = Database.connection(
      options[:database_url] || DEFAULT_DATABASE_URL
    )
  end

  @db ||= Database.connection(
    options[:database_url] || DEFAULT_DATABASE_URL
  )
end

.group(new_group, &block) ⇒ Object



56
57
58
# File 'lib/slimer.rb', line 56

def self.group(new_group, &block)
  options[:groups] += GroupConfigurator.group(new_group, &block).all
end

.groups(new_groups = nil) ⇒ Object



47
48
49
50
# File 'lib/slimer.rb', line 47

def self.groups(new_groups = nil)
  self.groups = new_groups if new_groups
  options[:groups]
end

.groups=(new_groups = Set.new(options[:groups].dup)) ⇒ Object



52
53
54
# File 'lib/slimer.rb', line 52

def self.groups=(new_groups = Set.new(options[:groups].dup))
  @options[:groups] = Set.new(new_groups.map(&:to_s))
end

.loggerObject



90
91
92
# File 'lib/slimer.rb', line 90

def self.logger
  @logger ||= Logger.new($stdout, level: Logger::INFO)
end

.logger=(logger) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/slimer.rb', line 94

def self.logger=(logger)
  if logger.nil?
    self.logger.level = Logger::FATAL
    return self.logger
  end

  @logger = logger
end

.optionsObject



24
25
26
# File 'lib/slimer.rb', line 24

def self.options
  @options ||= DEFAULTS.dup
end

.options=(opts) ⇒ Object



28
29
30
# File 'lib/slimer.rb', line 28

def self.options=(opts)
  @options = DEFAULTS.merge(opts)
end

.reset!Object



103
104
105
106
107
# File 'lib/slimer.rb', line 103

def self.reset!
  @options = DEFAULTS.dup
  truncate_tables!
  @db = nil
end

.sidekiq_queue(new_queue = nil) ⇒ Object



69
70
71
72
# File 'lib/slimer.rb', line 69

def self.sidekiq_queue(new_queue = nil)
  self.sidekiq_queue = new_queue if new_queue
  options[:sidekiq_queue]
end

.sidekiq_queue=(new_queue) ⇒ Object



74
75
76
# File 'lib/slimer.rb', line 74

def self.sidekiq_queue=(new_queue)
  @options[:sidekiq_queue] = new_queue
end

.truncate_tables!Object



109
110
111
112
# File 'lib/slimer.rb', line 109

def self.truncate_tables!
  Slimer::ApiKey.truncate if defined? Slimer::ApiKey
  Slimer::Substance.truncate if defined? Slimer::Substance
end