Class: Kangaru::Database

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Attributable
Defined in:
lib/kangaru/database.rb

Constant Summary collapse

PLUGINS =
%i[
  enum
  timestamps
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attributable

#initialize, #merge!

Methods included from Concern

#append_features, #class_methods, #included

Instance Attribute Details

#adaptorObject

Returns the value of attribute adaptor.



12
13
14
# File 'lib/kangaru/database.rb', line 12

def adaptor
  @adaptor
end

#handlerObject (readonly)

Returns the value of attribute handler.



14
15
16
# File 'lib/kangaru/database.rb', line 14

def handler
  @handler
end

#migration_pathObject

Returns the value of attribute migration_path.



12
13
14
# File 'lib/kangaru/database.rb', line 12

def migration_path
  @migration_path
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/kangaru/database.rb', line 12

def path
  @path
end

Instance Method Details

#migrate!Object



25
26
27
28
29
30
31
32
# File 'lib/kangaru/database.rb', line 25

def migrate!
  return unless handler
  return unless migrations_exist?

  Sequel.extension(:migration)

  Sequel::Migrator.run(handler, migration_path)
end

#setup!Object



16
17
18
19
20
21
22
23
# File 'lib/kangaru/database.rb', line 16

def setup!
  raise "adaptor can't be blank" if adaptor.nil?

  @handler = case adaptor
             when :sqlite then setup_sqlite!
             else raise "invalid adaptor '#{adaptor}'"
             end
end