Class: DbAgile::Environment
- Inherits:
-
Object
- Object
- DbAgile::Environment
- Includes:
- Buffering, Interactions, OnError, Repository
- Defined in:
- lib/dbagile/environment.rb,
lib/dbagile/environment/testing.rb,
lib/dbagile/environment/on_error.rb,
lib/dbagile/environment/buffering.rb,
lib/dbagile/environment/delegator.rb,
lib/dbagile/environment/repository.rb,
lib/dbagile/environment/interactions.rb
Overview
Defines the contract to be an environment for dbagile.
Defined Under Namespace
Modules: Buffering, Delegator, Interactions, OnError, Repository, Testing
Instance Attribute Summary
Attributes included from Interactions
#asking_buffer, #message_buffer
Attributes included from Buffering
Attributes included from OnError
Class Method Summary collapse
-
.default(load_repository = false) ⇒ Object
Returns the default environment to use.
-
.default! ⇒ Object
Convenient method for Environment::default(true).
-
.default_repository_path ⇒ Object
Returns the default path to use for a repository.
Instance Method Summary collapse
-
#dup ⇒ Object
Duplicates the environment but removes any cached value (repository and so on).
-
#initialize ⇒ Environment
constructor
Creates a default Environment instance with following options:.
-
#with_testing_methods!(interactive = true) ⇒ Object
Installs the testing methods, StringIO on output buffers then returns self.
Methods included from Repository
#each_database, #friendly_repository_path, #repository, #repository_exists?, #repository_path, #repository_path=, #with_connection, #with_current_connection, #with_current_database, #with_database, #with_repository
Methods included from Interactions
#ask, #ask!, #color, #console_width, #console_width=, #display, #interaction_highline, #interactive!, #interactive=, #interactive?, #say
Methods included from Buffering
Methods included from OnError
Constructor Details
#initialize ⇒ Environment
Creates a default Environment instance with following options:
-
repository_path -> what Environment::default_repository_path returns
-
input_buffer -> STDIN
-
output_buffer -> STDOUT
-
interactive? -> true
-
asking_buffer -> STDIN
-
message_buffer -> STDERR
-
show_backtrace -> false
41 42 43 44 45 46 47 48 49 |
# File 'lib/dbagile/environment.rb', line 41 def initialize @repository_path = Environment::default_repository_path @input_buffer = STDIN @output_buffer = STDOUT @interactive = true @asking_buffer = STDIN @message_buffer = STDERR @show_backtrace = false end |
Class Method Details
.default(load_repository = false) ⇒ Object
Returns the default environment to use.
The algorithm implemented tries to locate a repository folder in the following order:
-
dbagile.idx file in the current directory -> it’s parent folder
-
dbagile folder in the current directory -> ./dbagile
-
.dbagile folder in user’s home -> ~/.dbagile
If none of those files exists, a default environment will be created mapping to an unexisting repository folder in ~/.dbagile
By default, the repository is not loaded at all, and errors can therefore occur later, when the repository will be first accessed. Set load_repository to true to force immediate load.
106 107 108 109 110 111 112 |
# File 'lib/dbagile/environment.rb', line 106 def self.default(load_repository = false) env = Environment.new if load_repository env.repository end env end |
.default! ⇒ Object
Convenient method for Environment::default(true)
117 118 119 |
# File 'lib/dbagile/environment.rb', line 117 def self.default! Environment::default(true) end |
.default_repository_path ⇒ Object
Returns the default path to use for a repository.
The algorithm implemented tries to locate a repository folder in the following order:
-
dbagile.idx file in the current directory -> it’s parent folder
-
dbagile folder in the current directory -> ./dbagile
-
.dbagile folder in user’s home -> ~/.dbagile
If none of those files exists, ~/.dbagile is returned
79 80 81 82 83 84 85 86 87 |
# File 'lib/dbagile/environment.rb', line 79 def self.default_repository_path if File.exists?("./dbagile.idx") "." elsif File.exists?("dbagile") "dbagile" else File.join(ENV['HOME'], '.dbagile') end end |
Instance Method Details
#dup ⇒ Object
Duplicates the environment but removes any cached value (repository and so on)
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dbagile/environment.rb', line 55 def dup env = Environment.new env.repository_path = self.repository_path env.input_buffer = self.input_buffer env.output_buffer = self.output_buffer env.interactive = self.interactive? env.asking_buffer = self.asking_buffer env. = self. env.show_backtrace = self.show_backtrace? env end |
#with_testing_methods!(interactive = true) ⇒ Object
Installs the testing methods, StringIO on output buffers then returns self
21 22 23 24 25 26 27 28 |
# File 'lib/dbagile/environment.rb', line 21 def with_testing_methods!(interactive = true) require 'dbagile/environment/testing' extend(DbAgile::Environment::Testing) self.output_buffer = StringIO.new self. = StringIO.new self.interactive = interactive self end |