Module: Legion::Data::Local
- Defined in:
- lib/legion/data/local.rb
Class Attribute Summary collapse
-
.connection ⇒ Object
readonly
Returns the value of attribute connection.
-
.db_path ⇒ Object
readonly
Returns the value of attribute db_path.
Class Method Summary collapse
- .connected? ⇒ Boolean
- .model(table_name) ⇒ Object
- .register_migrations(name:, path:) ⇒ Object
- .registered_migrations ⇒ Object
- .reset! ⇒ Object
- .setup(database: nil) ⇒ Object
- .shutdown ⇒ Object
Class Attribute Details
.connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/legion/data/local.rb', line 10 def connection @connection end |
.db_path ⇒ Object (readonly)
Returns the value of attribute db_path.
10 11 12 |
# File 'lib/legion/data/local.rb', line 10 def db_path @db_path end |
Class Method Details
.connected? ⇒ Boolean
29 30 31 |
# File 'lib/legion/data/local.rb', line 29 def connected? @connected == true end |
.model(table_name) ⇒ Object
43 44 45 46 47 |
# File 'lib/legion/data/local.rb', line 43 def model(table_name) raise 'Legion::Data::Local not connected' unless connected? ::Sequel::Model(connection[table_name]) end |
.register_migrations(name:, path:) ⇒ Object
33 34 35 36 37 |
# File 'lib/legion/data/local.rb', line 33 def register_migrations(name:, path:) @registered_migrations ||= {} @registered_migrations[name] = path run_single_migration(name, path) if connected? end |
.registered_migrations ⇒ Object
39 40 41 |
# File 'lib/legion/data/local.rb', line 39 def registered_migrations @registered_migrations || {} end |
.reset! ⇒ Object
49 50 51 52 53 54 |
# File 'lib/legion/data/local.rb', line 49 def reset! @connection = nil @connected = false @db_path = nil @registered_migrations = nil end |
.setup(database: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/data/local.rb', line 12 def setup(database: nil, **) return if @connected db_file = database || local_settings[:database] || 'legionio_local.db' @db_path = db_file @connection = ::Sequel.sqlite(db_file) @connected = true run_migrations Legion::Logging.info "Legion::Data::Local connected to #{db_file}" if defined?(Legion::Logging) end |
.shutdown ⇒ Object
23 24 25 26 27 |
# File 'lib/legion/data/local.rb', line 23 def shutdown @connection&.disconnect @connection = nil @connected = false end |