Class: Yarr::Database

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

Overview

Handles connecting to sequel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connector = :sqlite) ⇒ Database

Connection to the database

Parameters:

  • connector (symbol) (defaults to: :sqlite)

    the database connector


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yarr/database.rb', line 12

def initialize(connector = :sqlite)
  @db_dir = File.join(PROJECT_ROOT, 'db')
  @db_path = File.join(@db_dir, Yarr.config.test? ? 'test' : 'database')

  @db = Sequel.public_send(connector, @db_path)

  (@db.methods - methods).each do |method|
    self.class.class_eval do
      def_delegator :@db, method
    end
  end
end

Instance Attribute Details

#db_dirObject (readonly)

Returns the value of attribute db_dir


29
# File 'lib/yarr/database.rb', line 29

attr_reader :db_path, :db_dir

#db_pathString (readonly)

Returns path to the database file.

Returns:

  • (String)

    path to the database file


29
30
31
# File 'lib/yarr/database.rb', line 29

def db_path
  @db_path
end