[](key, scope = nil)
click to toggle source
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)
click to toggle source
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()
click to toggle source
def env
memo(__method__) { HashSource.new(adapter_name, :name => "environment", :raw => env_source_data) }
end
global()
click to toggle source
def global
memo(__method__) { new_file_source(global_config_path) }
end
keys()
click to toggle source
def keys
[local, env, global].inject([]){|a, e| a.concat(e.keys) ; a}.sort.uniq
end
local()
click to toggle source
def local
memo(__method__) { new_file_source(local_config_path) }
end
lockfile_name()
click to toggle source
def lockfile_name
"#{specfile_name}.lock"
end
lockfile_path()
click to toggle source
def lockfile_path
project_path + lockfile_name
end
project_path()
click to toggle source
def project_path
root || specfile_path.dirname
end
specfile_name()
click to toggle source
def specfile_name
specfile_path.basename.to_s
end
specfile_path()
click to toggle source
def specfile_path
if root
root + (assigned_specfile_name || default_specfile_name)
else
env_specfile_path || default_specfile_path
end
end
config_key()
click to toggle source
def config_key
"config"
end
config_name()
click to toggle source
def config_name
File.join(*[config_name_prefix, adapter_name, "config"])
end
config_name_prefix()
click to toggle source
def config_name_prefix
".#{library}"
end
default_global_config_path()
click to toggle source
def default_global_config_path
underlying_home && underlying_home + config_name
end
default_local_config_path()
click to toggle source
def default_local_config_path
default_project_root_path + config_name
end
default_project_root_path()
click to toggle source
def default_project_root_path
if root
root
else
path = underlying_pwd
path = path.dirname until project_root_path?(path) || path.dirname == path
project_root_path?(path) ? path : underlying_pwd
end
end
default_specfile_name()
click to toggle source
def default_specfile_name
"#{adapter_name.capitalize}file"
end
default_specfile_path()
click to toggle source
def default_specfile_path
default_project_root_path + (assigned_specfile_name || default_specfile_name)
end
env_global_config_path()
click to toggle source
def env_global_config_path
memo(__method__) { env[config_key] }
end
env_local_config_path()
click to toggle source
def env_local_config_path
return unless env_specfile_path
env_specfile_path.dirname + config_name
end
env_source_data()
click to toggle source
def env_source_data
prefix = raw_key_prefix
data = underlying_env.dup
data.reject!{|k, _| !k.start_with?(prefix) || k.size <= prefix.size}
data
end
env_specfile_path()
click to toggle source
def env_specfile_path
memo(__method__) do
path = env[specfile_key]
path && Pathname(path)
end
end
global_config_path()
click to toggle source
def global_config_path
env_global_config_path || default_global_config_path
end
library()
click to toggle source
def library
self.class.library
end
local_config_path()
click to toggle source
def local_config_path
root_local_config_path || env_local_config_path || default_local_config_path
end
memo(key) { || ... }
click to toggle source
def memo(key)
key = "@#{key}"
instance_variable_set(key, yield) unless instance_variable_defined?(key)
instance_variable_get(key)
end
new_file_source(config_path)
click to toggle source
def new_file_source(config_path)
return unless config_path
FileSource.new(adapter_name,
:config_path => config_path,
:forbidden_keys => [config_key, specfile_key]
)
end
project_root_path?(path)
click to toggle source
def project_root_path?(path)
File.file?(path + default_specfile_name)
end
raw_key_prefix()
click to toggle source
def raw_key_prefix
"#{library.upcase}_#{adapter_name.upcase}_"
end
root_local_config_path()
click to toggle source
def root_local_config_path
root && root + config_name
end
specfile_key()
click to toggle source
def specfile_key
"#{adapter_name}file"
end