Module: Litesupport
- Defined in:
- lib/litestack/litesupport.rb
Defined Under Namespace
Modules: ForkListener, Forkable, Liteconnection Classes: Error, Mutex, Pool
Class Method Summary collapse
-
.create_db(path) ⇒ Object
common db object options.
-
.detect_environment ⇒ Object
Detect the Rack or Rails environment.
-
.detect_root(env) ⇒ Object
Default path where we’ll store all of the databases.
- .ensure_root_volume(path) ⇒ Object
- .environment ⇒ Object
-
.root(env = Litesupport.environment) ⇒ Object
Databases will be stored by default at this path.
Class Method Details
.create_db(path) ⇒ Object
common db object options
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/litestack/litesupport.rb', line 34 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_environment ⇒ Object
Detect the Rack or Rails environment.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/litestack/litesupport.rb', line 17 def self.detect_environment if defined?(Rails) && Rails.respond_to?(:env) 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.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/litestack/litesupport.rb', line 51 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
63 64 65 66 |
# File 'lib/litestack/litesupport.rb', line 63 def self.ensure_root_volume(path) FileUtils.mkdir_p path unless path.exist? path end |
.environment ⇒ Object
29 30 31 |
# File 'lib/litestack/litesupport.rb', line 29 def self.environment @environment ||= detect_environment end |
.root(env = Litesupport.environment) ⇒ Object
Databases will be stored by default at this path.
46 47 48 |
# File 'lib/litestack/litesupport.rb', line 46 def self.root(env = Litesupport.environment) ensure_root_volume detect_root(env) end |