Sha256: d84ed67d1614e99b9db3a1536089b92b9ed9a535fdf2803cd0dbb4f286e58ed0

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'lotus/utils/class'

module Lotus
  module Commands
    class DB
      class Console
        attr_reader :name, :env_options, :environment

        def initialize(name, environment)
          @name        = name
          @environment = environment
          @env_options = environment.to_options
          @environment.require_application_environment
        end

        def start
          exec connection_string
        end

        private

        def config
          if name
            app_constant = Lotus::Utils::Class.load_from_pattern!(Lotus::Utils::String.new(name).classify)
            Lotus::Utils::Class.load_from_pattern!("#{app_constant}::Application").load!
            Lotus::Utils::Class.load_from_pattern!("#{app_constant}::Model").configuration
          else
            Lotus::Model.configuration
          end
        end

        def adapter_config
          config.adapter_config
        end

        def mapper
          config.mapper
        end

        def adapter_class
          Lotus::Utils::Class.load_from_pattern!(adapter_config.class_name, Lotus::Model::Adapters)
        end

        def connection_string
          adapter_class.new(mapper, adapter_config.uri).connection_string
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lotusrb-0.5.0 lib/lotus/commands/db/console.rb
lotusrb-0.4.1 lib/lotus/commands/db/console.rb
lotusrb-0.4.0 lib/lotus/commands/db/console.rb