Class: Yerba::Yerbafile

Inherits:
Object
  • Object
show all
Defined in:
lib/yerba/yerbafile.rb,
ext/yerba/yerba.c

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Yerbafile

Returns a new instance of Yerbafile.

Raises:



7
8
9
10
11
# File 'lib/yerba/yerbafile.rb', line 7

def initialize(path)
  @path = File.expand_path(path)

  raise Yerba::Error, "Yerbafile not found: #{path}" unless File.exist?(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/yerba/yerbafile.rb', line 5

def path
  @path
end

Class Method Details

.apply!(document, yerbafile = nil) ⇒ Object



31
32
33
# File 'lib/yerba/yerbafile.rb', line 31

def self.apply!(document, yerbafile = nil)
  resolve(yerbafile).apply(document)
end

.find(directory = Dir.pwd) ⇒ Object



13
14
15
16
17
# File 'lib/yerba/yerbafile.rb', line 13

def self.find(directory = Dir.pwd)
  path = locate(directory)

  path ? new(path) : nil
end

.find!(directory = Dir.pwd) ⇒ Object



19
20
21
# File 'lib/yerba/yerbafile.rb', line 19

def self.find!(directory = Dir.pwd)
  find(directory) || raise(Yerba::Error, "No Yerbafile found")
end

.locate(*args) ⇒ Object

Yerbafile.locate(directory = nil) → path string or nil



805
806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'ext/yerba/yerba.c', line 805

static VALUE yerbafile_s_locate(int argc, VALUE *argv, VALUE klass) {
  VALUE directory;
  rb_scan_args(argc, argv, "01", &directory);

  const char *dir = NIL_P(directory) ? NULL : StringValueCStr(directory);
  char *result = yerba_yerbafile_find(dir);

  if (!result) return Qnil;

  VALUE path = make_utf8_string(result);
  yerba_string_free(result);

  return path;
}

.resolve(yerbafile = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/yerba/yerbafile.rb', line 23

def self.resolve(yerbafile = nil)
  case yerbafile
  when Yerbafile then yerbafile
  when String then new(yerbafile)
  when true, nil then find!
  end
end

Instance Method Details

#apply(document) ⇒ Object



35
36
37
38
39
# File 'lib/yerba/yerbafile.rb', line 35

def apply(document)
  document.apply_yerbafile(@path)

  document
end

#inspectObject



41
42
43
# File 'lib/yerba/yerbafile.rb', line 41

def inspect
  "#<Yerba::Yerbafile path=#{@path.inspect}>"
end