lib/cupper/cupperfile.rb in cupper-0.1.3 vs lib/cupper/cupperfile.rb in cupper-0.2.0
- old
+ new
@@ -1,22 +1,44 @@
module Cupper
class Cupperfile
- def initialize(loader, keys)
- @keys = keys
- @loader = loader
- @config, _ = loader.load(keys)
+ def initialize(key)
+ @key = key
+ @config, _ = Cupper::Config.load(key)
end
- protected
+ def machine_being_read(name, env)
+ # Load the configuration for the machine
+ results = cupper_config(name, env)
+ config = results[:config]
- def find_cupperfile(search_path)
- ["Cupperfile", "cupperfile"].each do |cupperfile|
- current_path = search_path.join(cupperfile)
- return current_path if current_path.file?
- end
+ # Create the machine and cache it for future calls. This will also
+ # return the machine from this method.
+ return new_machine(name, config, env)
+ end
- nil
+ def new_machine(name, config, env)
+ machine = Attribute.new
+ class << machine
+ attr_accessor :name
+ attr_accessor :config
+ attr_accessor :env
+ end
+ machine.name = name
+ machine.config = config
+ machine.env = env
+ machine
end
+ def cupper_config(name, env)
+ cupperfile = env.find_cupperfile(env.root_path)
+ if cupperfile
+ config = Cupper::Config.load(cupperfile)
+ end
+
+ return {
+ config: config,
+ # TODO: add other meaningfull returns
+ }
+ end
end
end