Class: Eksa::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/eksa/model.rb

Direct Known Subclasses

Pesan

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.database_pathObject

Returns the value of attribute database_path.



7
8
9
# File 'lib/eksa/model.rb', line 7

def database_path
  @database_path
end

Class Method Details

.dbObject



10
11
12
13
14
15
16
17
18
# File 'lib/eksa/model.rb', line 10

def self.db
  path = database_path || default_db_path
  db_dir = File.dirname(path)
  FileUtils.mkdir_p(db_dir) unless Dir.exist?(db_dir)
  
  @db ||= SQLite3::Database.new(path)
  ensure_schema
  @db
end

.default_db_pathObject



20
21
22
# File 'lib/eksa/model.rb', line 20

def self.default_db_path
  File.expand_path("../../db/eksa_app.db", __dir__)
end

.ensure_schemaObject



24
25
26
27
28
# File 'lib/eksa/model.rb', line 24

def self.ensure_schema
  return if @schema_initialized
  @schema_initialized = true
  setup_schema if respond_to?(:setup_schema)
end