lib/eac_launcher/context.rb in eac_launcher-0.1.4 vs lib/eac_launcher/context.rb in eac_launcher-0.1.5
- old
+ new
@@ -1,36 +1,52 @@
module EacLauncher
class Context
include ::Eac::SimpleCache
+ DEFAULT_PROJECTS_ROOT = '.'.freeze
+ DEFAULT_SETTINGS_FILE = ::File.join(ENV['HOME'], '.config', 'eac_launcher', 'settings.yml')
+ DEFAULT_CACHE_ROOT = ::File.join(ENV['HOME'], '.cache', 'eac_launcher')
+
class << self
+ attr_writer :current
+
def current
- default
+ @current ||= default
end
def default
- @default ||= Context.new(
- ENV['EAC_LAUNCHER_PROJECTS_ROOT'] || '.',
- ENV['EAC_LAUNCHER_SETTINGS_FILE'] ||
- ::File.join(ENV['HOME'], '.config', 'eac_launcher', 'settings.yml')
- )
+ @default ||= Context.new
end
end
- attr_reader :root, :settings
+ attr_reader :root, :settings, :cache_root
attr_accessor :publish_options
- def initialize(projects_root, settings_file)
- @root = ::EacLauncher::Instances::Base.new(projects_root, nil)
- @settings = ::EacLauncher::Context::Settings.new(settings_file)
+ def initialize(options = {})
+ @options = options.with_indifferent_access
+ @root = ::EacLauncher::Instances::Base.new(build_option(:projects_root), nil)
+ @settings = ::EacLauncher::Context::Settings.new(build_option(:settings_file))
+ @cache_root = build_option(:cache_root)
@publish_options = { new: false, confirm: false, stereotype: nil }
end
- def cache_root
- File.join(ENV['HOME'], '.cache', 'cli-utils', 'dev')
+ def instance(to_root_path)
+ instances.find { |i| i.to_root_path == to_root_path }
end
private
+
+ def build_option(key)
+ @options[key] || env_option(key) || default_option(key)
+ end
+
+ def env_option(key)
+ ENV["EAC_LAUNCHER_#{key}".underscore.upcase]
+ end
+
+ def default_option(key)
+ self.class.const_get("DEFAULT_#{key}".underscore.upcase)
+ end
def projects_uncached
r = {}
instances.each do |i|
r[i.basename] ||= []