Class: Vagabond::Vagabondfile

Inherits:
Object
  • Object
show all
Defined in:
lib/vagabond/vagabondfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Vagabondfile

Returns a new instance of Vagabondfile.



9
10
11
12
13
# File 'lib/vagabond/vagabondfile.rb', line 9

def initialize(path=nil)
  path = discover_path(Dir.pwd) unless path
  @path = path
  load_configuration!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/vagabond/vagabondfile.rb', line 7

def config
  @config
end

#pathObject (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



15
16
17
# File 'lib/vagabond/vagabondfile.rb', line 15

def [](k)
  @config[k]
end

#discover_path(path) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/vagabond/vagabondfile.rb', line 24

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

#load_configuration!Object



19
20
21
22
# File 'lib/vagabond/vagabondfile.rb', line 19

def load_configuration!
  raise 'No Vagabondfile file found!' unless @path && File.exists?(@path)
  @config = Mash.new(self.instance_eval(IO.read(@path), @path, 1))
end