Class: Librarian::Config::Database
- Inherits:
-
Object
- Object
- Librarian::Config::Database
- Defined in:
- lib/librarian/config/database.rb
Instance Attribute Summary collapse
-
#adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
-
#assigned_specfile_name ⇒ Object
readonly
Returns the value of attribute assigned_specfile_name.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#underlying_env ⇒ Object
readonly
Returns the value of attribute underlying_env.
-
#underlying_home ⇒ Object
readonly
Returns the value of attribute underlying_home.
-
#underlying_pwd ⇒ Object
readonly
Returns the value of attribute underlying_pwd.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key, scope = nil) ⇒ Object
- #[]=(key, scope, value) ⇒ Object
- #env ⇒ Object
- #global ⇒ Object
-
#initialize(adapter_name, options = { }) ⇒ Database
constructor
A new instance of Database.
- #keys ⇒ Object
- #local ⇒ Object
- #lockfile_name ⇒ Object
- #lockfile_path ⇒ Object
- #project_path ⇒ Object
- #specfile_name ⇒ Object
- #specfile_path ⇒ Object
Constructor Details
#initialize(adapter_name, options = { }) ⇒ Database
Returns a new instance of Database.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/librarian/config/database.rb', line 25 def initialize(adapter_name, = { }) self.adapter_name = adapter_name or raise ArgumentError, "must provide adapter_name" [:project_path] || [:pwd] or raise ArgumentError, "must provide project_path or pwd" self.root = [:project_path] && Pathname([:project_path]) self.assigned_specfile_name = [:specfile_name] self. = [:env] or raise ArgumentError, "must provide env" self. = [:pwd] && Pathname([:pwd]) self. = [:home] && Pathname([:home]) end |
Instance Attribute Details
#adapter_name ⇒ Object
Returns the value of attribute adapter_name.
16 17 18 |
# File 'lib/librarian/config/database.rb', line 16 def adapter_name @adapter_name end |
#assigned_specfile_name ⇒ Object
Returns the value of attribute assigned_specfile_name.
19 20 21 |
# File 'lib/librarian/config/database.rb', line 19 def assigned_specfile_name @assigned_specfile_name end |
#root ⇒ Object
Returns the value of attribute root.
19 20 21 |
# File 'lib/librarian/config/database.rb', line 19 def root @root end |
#underlying_env ⇒ Object
Returns the value of attribute underlying_env.
22 23 24 |
# File 'lib/librarian/config/database.rb', line 22 def @underlying_env end |
#underlying_home ⇒ Object
Returns the value of attribute underlying_home.
22 23 24 |
# File 'lib/librarian/config/database.rb', line 22 def @underlying_home end |
#underlying_pwd ⇒ Object
Returns the value of attribute underlying_pwd.
22 23 24 |
# File 'lib/librarian/config/database.rb', line 22 def @underlying_pwd end |
Class Method Details
.library ⇒ Object
11 12 13 |
# File 'lib/librarian/config/database.rb', line 11 def library name.split("::").first.downcase end |
Instance Method Details
#[](key, scope = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/librarian/config/database.rb', line 49 def [](key, scope = nil) case scope when "local", :local then local[key] when "env", :env then env[key] when "global", :global then global[key] when nil then local[key] || env[key] || global[key] else raise Error, "bad scope" end end |
#[]=(key, scope, value) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/librarian/config/database.rb', line 59 def []=(key, scope, value) case scope when "local", :local then local[key] = value when "global", :global then global[key] = value else raise Error, "bad scope" end end |
#env ⇒ Object
41 42 43 |
# File 'lib/librarian/config/database.rb', line 41 def env memo(__method__) { HashSource.new(adapter_name, :name => "environment", :raw => env_source_data) } end |
#global ⇒ Object
37 38 39 |
# File 'lib/librarian/config/database.rb', line 37 def global memo(__method__) { new_file_source(global_config_path) } end |
#keys ⇒ Object
67 68 69 |
# File 'lib/librarian/config/database.rb', line 67 def keys [local, env, global].inject([]){|a, e| a.concat(e.keys) ; a}.sort.uniq end |
#local ⇒ Object
45 46 47 |
# File 'lib/librarian/config/database.rb', line 45 def local memo(__method__) { new_file_source(local_config_path) } end |
#lockfile_name ⇒ Object
91 92 93 |
# File 'lib/librarian/config/database.rb', line 91 def lockfile_name "#{specfile_name}.lock" end |
#lockfile_path ⇒ Object
87 88 89 |
# File 'lib/librarian/config/database.rb', line 87 def lockfile_path project_path + lockfile_name end |
#project_path ⇒ Object
71 72 73 |
# File 'lib/librarian/config/database.rb', line 71 def project_path root || specfile_path.dirname end |
#specfile_name ⇒ Object
83 84 85 |
# File 'lib/librarian/config/database.rb', line 83 def specfile_name specfile_path.basename.to_s end |