Class: Caterer::Environment
- Inherits:
-
Object
- Object
- Caterer::Environment
- Defined in:
- lib/caterer/environment.rb
Instance Attribute Summary collapse
-
#caterfile_name ⇒ Object
readonly
Returns the value of attribute caterfile_name.
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
- #action_registry ⇒ Object
- #action_runner ⇒ Object
- #cli(*args) ⇒ Object
- #config ⇒ Object (also: #load!)
-
#initialize(opts = {}) ⇒ Environment
constructor
A new instance of Environment.
- #load_config_file(file) ⇒ Object
- #load_custom_config ⇒ Object
- #load_default_config ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Environment
Returns a new instance of Environment.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/caterer/environment.rb', line 9 def initialize(opts={}) opts = { :cwd => nil, :caterfile_name => nil, :ui_class => nil, :custom_config => nil }.merge(opts) opts[:cwd] ||= ENV["CATERER_CWD"] if ENV.has_key?("CATERER_CWD") opts[:cwd] ||= Dir.pwd opts[:caterfile_name] ||= [] opts[:caterfile_name] = [opts[:caterfile_name]] if !opts[:caterfile_name].is_a?(Array) opts[:caterfile_name] += ["Caterfile"] @cwd = Pathname.new(opts[:cwd]) @caterfile_name = opts[:caterfile_name] @custom_config = opts[:custom_config] ui_class = opts[:ui_class] || Vli::UI::Silent @ui = ui_class.new("cater") end |
Instance Attribute Details
#caterfile_name ⇒ Object (readonly)
Returns the value of attribute caterfile_name.
7 8 9 |
# File 'lib/caterer/environment.rb', line 7 def caterfile_name @caterfile_name end |
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
7 8 9 |
# File 'lib/caterer/environment.rb', line 7 def cwd @cwd end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
7 8 9 |
# File 'lib/caterer/environment.rb', line 7 def ui @ui end |
Instance Method Details
#action_registry ⇒ Object
47 48 49 |
# File 'lib/caterer/environment.rb', line 47 def action_registry Caterer.actions end |
#action_runner ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/caterer/environment.rb', line 33 def action_runner @action_runner ||= Vli::Action::Runner.new(action_registry) do { :action_runner => action_runner, :ui => ui, :uuid => uuid } end end |
#cli(*args) ⇒ Object
80 81 82 |
# File 'lib/caterer/environment.rb', line 80 def cli(*args) Cli.new(args.flatten, self).execute end |
#config ⇒ Object Also known as: load!
51 52 53 54 55 56 57 |
# File 'lib/caterer/environment.rb', line 51 def config @config ||= begin load_default_config load_custom_config Caterer.config end end |
#load_config_file(file) ⇒ Object
76 77 78 |
# File 'lib/caterer/environment.rb', line 76 def load_config_file(file) load file if File.exists? file end |
#load_custom_config ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/caterer/environment.rb', line 64 def load_custom_config if @custom_config # if it's been explicitly defined, load it load_config_file @custom_config else # lets try a few variations @caterfile_name.each do |config_file| load_config_file "#{@cwd}/#{config_file}" end end end |
#load_default_config ⇒ Object
60 61 62 |
# File 'lib/caterer/environment.rb', line 60 def load_default_config require_relative '../../config/default' end |
#uuid ⇒ Object
43 44 45 |
# File 'lib/caterer/environment.rb', line 43 def uuid @uuid ||= ::Digest::MD5.hexdigest(@cwd.to_s) end |