From e5ed1ba2df6f735e32de35d9171d572dce322b7f Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 28 Nov 2012 20:14:05 -0800 Subject: new system for how directory paths work. now there is a file Leapfile that manages this, instead of it always being ../leap_platform --- lib/leap_cli/leapfile.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/leap_cli/leapfile.rb (limited to 'lib/leap_cli/leapfile.rb') diff --git a/lib/leap_cli/leapfile.rb b/lib/leap_cli/leapfile.rb new file mode 100644 index 0000000..2559864 --- /dev/null +++ b/lib/leap_cli/leapfile.rb @@ -0,0 +1,43 @@ +# +# The Leapfile is the bootstrap configuration file for a LEAP provider. +# +# It is akin to a Gemfile, Rakefile, or Capfile (e.g. it is a ruby file that gets eval'ed) +# + +module LeapCli + def self.leapfile + @leapfile ||= Leapfile.new + end + + class Leapfile + attr_accessor :platform_directory_path + attr_accessor :provider_directory_path + + def load + directory = File.expand_path(find_in_directory_tree('Leapfile')) + if directory == '/' + return nil + else + self.provider_directory_path = directory + leapfile = directory + '/Leapfile' + instance_eval(File.read(leapfile), leapfile) + self.platform_directory_path = File.expand_path(self.platform_directory_path || '../leap_platform', self.provider_directory_path) + return true + end + end + + private + + def find_in_directory_tree(filename) + search_dir = Dir.pwd + while search_dir != "/" + Dir.foreach(search_dir) do |f| + return search_dir if f == filename + end + search_dir = File.dirname(search_dir) + end + return search_dir + end + end +end + -- cgit v1.2.3