Module: Litesupport

Defined in:
lib/litestack/litesupport.rb

Defined Under Namespace

Modules: ForkListener, Forkable, Liteconnection Classes: Error, Mutex, Pool

Class Method Summary collapse

Class Method Details

.create_db(path) ⇒ Object

common db object options



33
34
35
36
37
38
39
40
41
42
# File 'lib/litestack/litesupport.rb', line 33

def self.create_db(path)
  db = SQLite3::Database.new(path)
  db.busy_handler { Litescheduler.switch || sleep(0.0001) }
  db.journal_mode = "WAL"
  db.instance_variable_set(:@stmts, {})
  class << db
    attr_reader :stmts
  end
  db
end

.detect_environmentObject

Detect the Rack or Rails environment.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/litestack/litesupport.rb', line 16

def self.detect_environment
  if defined? Rails
    Rails.env
  elsif ENV["RACK_ENV"]
    ENV["RACK_ENV"]
  elsif ENV["APP_ENV"]
    ENV["APP_ENV"]
  else
    "development"
  end
end

.detect_root(env) ⇒ Object

Default path where we’ll store all of the databases.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/litestack/litesupport.rb', line 50

def self.detect_root(env)
  path = if ENV["LITESTACK_DATA_PATH"]
    ENV["LITESTACK_DATA_PATH"]
  elsif defined? Rails
    "./db"
  else
    "."
  end

  Pathname.new(path).join(env)
end

.ensure_root_volume(path) ⇒ Object



62
63
64
65
# File 'lib/litestack/litesupport.rb', line 62

def self.ensure_root_volume(path)
  FileUtils.mkdir_p path unless path.exist?
  path
end

.environmentObject



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

def self.environment
  @environment ||= detect_environment
end

.root(env = Litesupport.environment) ⇒ Object

Databases will be stored by default at this path.



45
46
47
# File 'lib/litestack/litesupport.rb', line 45

def self.root(env = Litesupport.environment)
  ensure_root_volume detect_root(env)
end