Class: Vagabond::Vagabondfile
- Inherits:
-
Object
- Object
- Vagabond::Vagabondfile
- Defined in:
- lib/vagabond/vagabondfile.rb
Constant Summary collapse
- DEFAULT_KEYS =
%w(boxes mappings test_mappings spec_mappings local_chef_server)
- ALIASES =
Mash.new(:boxes => :nodes, :nodes => :boxes)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #[](k) ⇒ Object
- #aliased(k) ⇒ Object
- #directory ⇒ Object
- #discover_path(path) ⇒ Object
- #generate_store_path ⇒ Object
-
#initialize(path = nil, *args) ⇒ Vagabondfile
constructor
A new instance of Vagabondfile.
- #load_configuration!(*args) ⇒ Object
- #local_chef_server? ⇒ Boolean
- #store_directory ⇒ Object
- #store_path ⇒ Object
Constructor Details
#initialize(path = nil, *args) ⇒ Vagabondfile
Returns a new instance of Vagabondfile.
12 13 14 15 16 |
# File 'lib/vagabond/vagabondfile.rb', line 12 def initialize(path=nil, *args) path = discover_path(Dir.pwd) unless path @path = path load_configuration!(args.include?(:allow_missing)) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/vagabond/vagabondfile.rb', line 7 def config @config end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/vagabond/vagabondfile.rb', line 6 def path @path end |
Instance Method Details
#[](k) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/vagabond/vagabondfile.rb', line 18 def [](k) if(DEFAULT_KEYS.include?(k.to_s)) @config[k] ||= Mash.new end aliased(k) || @config[k] end |
#aliased(k) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagabond/vagabondfile.rb', line 25 def aliased(k) if(ALIASES.has_key?(k)) v = [@config[k], @config[ALIASES[k]]].compact if(v.size > 1) case v.first when Array m = :| when Hash, Mash m = :merge else m = :+ end v.inject(&m) else v.first end end end |
#directory ⇒ Object
72 73 74 |
# File 'lib/vagabond/vagabondfile.rb', line 72 def directory File.dirname(@path) end |
#discover_path(path) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/vagabond/vagabondfile.rb', line 80 def discover_path(path) d_path = Dir.glob(File.join(path, 'Vagabondfile')).first unless(d_path) cut_path = path.split(File::SEPARATOR) cut_path.pop d_path = discover_path(cut_path.join(File::SEPARATOR)) unless cut_path.empty? end d_path end |
#generate_store_path ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/vagabond/vagabondfile.rb', line 60 def generate_store_path @path ||= File.(File.join(Dir.pwd, 'Vagabondfile')) @store_path = File.join('/tmp/vagabond-solos', directory.gsub(%r{[^0-9a-zA-Z]}, '-'), 'Vagabondfile') @store_path = File.(@store_path.gsub('-', '/')) FileUtils.mkdir_p(File.dirname(@store_path)) File.dirname(@store_path) end |
#load_configuration!(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vagabond/vagabondfile.rb', line 44 def load_configuration!(*args) unless(args.empty?) no_raise = args.first == true force_store = args.include?(:force_store_path) no_raise ||= force_store end if(@path && File.exists?(@path)) @config = Mash.new(self.instance_eval(IO.read(@path), @path, 1)) end if(!@config || force_store) raise 'No Vagabondfile file found!' unless no_raise generate_store_path @config = Mash[*DEFAULT_KEYS.map{|k| [k, Mash.new]}.flatten] end end |
#local_chef_server? ⇒ Boolean
90 91 92 |
# File 'lib/vagabond/vagabondfile.rb', line 90 def local_chef_server? self[:local_chef_server] && self[:local_chef_server][:enabled] end |
#store_directory ⇒ Object
76 77 78 |
# File 'lib/vagabond/vagabondfile.rb', line 76 def store_directory File.dirname(@store_path || @path) end |
#store_path ⇒ Object
68 69 70 |
# File 'lib/vagabond/vagabondfile.rb', line 68 def store_path @store_path || @path end |