Sha256: 50c17888f48eb026adacdf6a8ec43eec9ba089e63ce5a10a4755e4b210e62089

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'sequel'

module Pokeedex # :nodoc:
  ##
  # Class that holds the configuration of the gem and the database connection information
  # and methods to connect to the database and run the migrations if needed
  class Configuration
    ##
    # The name of the database file to use for the gem (default: pokeedex_local.sqlite3)
    attr_reader :db_name

    ##
    # The path to the database file to use for the gem (default: /path/to/pokeedex/db/pokeedex_local.sqlite3)
    attr_writer :db_path

    def initialize
      @db_name = 'pokeedex_local.sqlite3'
    end

    ##
    # Set the name of the database file to use for the gem and reset the path to the database file to nil
    def db_name=(name)
      @db_name = name
      @db_path = nil
    end

    ##
    # Return the path to the database file to use for the gem (default: /path/to/pokeedex/db/pokeedex_local.sqlite3)
    def db_path
      @db_path ||= File.join(Pokeedex.root_path, 'lib', 'pokeedex', 'db', db_name)
    end

    ##
    # Return the database connection to the database file to use for the gem (default: /path/to/pokeedex/db/pokeedex_local.sqlite3)
    def db_connection
      Sequel.sqlite(db_path)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pokeedex-0.1.5 lib/pokeedex/configuration.rb