Class: Librarian::Config::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/config/database.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = { })
  self.adapter_name = adapter_name or raise ArgumentError, "must provide adapter_name"

  options[:project_path] || options[:pwd] or raise ArgumentError, "must provide project_path or pwd"

  self.root = options[:project_path] && Pathname(options[:project_path])
  self.assigned_specfile_name = options[:specfile_name]
  self.underlying_env = options[:env] or raise ArgumentError, "must provide env"
  self.underlying_pwd = options[:pwd] && Pathname(options[:pwd])
  self.underlying_home = options[:home] && Pathname(options[:home])
end

Instance Attribute Details

#adapter_nameObject

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_nameObject

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

#rootObject

Returns the value of attribute root.



19
20
21
# File 'lib/librarian/config/database.rb', line 19

def root
  @root
end

#underlying_envObject

Returns the value of attribute underlying_env.



22
23
24
# File 'lib/librarian/config/database.rb', line 22

def underlying_env
  @underlying_env
end

#underlying_homeObject

Returns the value of attribute underlying_home.



22
23
24
# File 'lib/librarian/config/database.rb', line 22

def underlying_home
  @underlying_home
end

#underlying_pwdObject

Returns the value of attribute underlying_pwd.



22
23
24
# File 'lib/librarian/config/database.rb', line 22

def underlying_pwd
  @underlying_pwd
end

Class Method Details

.libraryObject



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

#envObject



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

#globalObject



37
38
39
# File 'lib/librarian/config/database.rb', line 37

def global
  memo(__method__) { new_file_source(global_config_path) }
end

#keysObject



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

#localObject



45
46
47
# File 'lib/librarian/config/database.rb', line 45

def local
  memo(__method__) { new_file_source(local_config_path) }
end

#lockfile_nameObject



91
92
93
# File 'lib/librarian/config/database.rb', line 91

def lockfile_name
  "#{specfile_name}.lock"
end

#lockfile_pathObject



87
88
89
# File 'lib/librarian/config/database.rb', line 87

def lockfile_path
  project_path + lockfile_name
end

#project_pathObject



71
72
73
# File 'lib/librarian/config/database.rb', line 71

def project_path
  root || specfile_path.dirname
end

#specfile_nameObject



83
84
85
# File 'lib/librarian/config/database.rb', line 83

def specfile_name
  specfile_path.basename.to_s
end

#specfile_pathObject



75
76
77
78
79
80
81
# File 'lib/librarian/config/database.rb', line 75

def specfile_path
  if root
    root + (assigned_specfile_name || default_specfile_name)
  else
    env_specfile_path || default_specfile_path
  end
end