Class: Qrpm::Lexer
- Inherits:
-
Object
- Object
- Qrpm::Lexer
- Defined in:
- lib/qrpm/lexer.rb
Instance Attribute Summary collapse
-
#absdirs ⇒ Object
readonly
Returns the value of attribute absdirs.
-
#reldirs ⇒ Object
readonly
Returns the value of attribute reldirs.
Class Method Summary collapse
-
.load_yaml(file) ⇒ Object
Is actually a kind of lexer.
Instance Method Summary collapse
-
#initialize(reldirs, absdirs) ⇒ Lexer
constructor
A new instance of Lexer.
- #lex(file) ⇒ Object
- #search(file) ⇒ Object
Constructor Details
#initialize(reldirs, absdirs) ⇒ Lexer
Returns a new instance of Lexer.
7 8 9 10 |
# File 'lib/qrpm/lexer.rb', line 7 def initialize(reldirs, absdirs) @reldirs = reldirs.map { |p| File.(p) } @absdirs = absdirs.map { |p| File.(p) } end |
Instance Attribute Details
#absdirs ⇒ Object (readonly)
Returns the value of attribute absdirs.
5 6 7 |
# File 'lib/qrpm/lexer.rb', line 5 def absdirs @absdirs end |
#reldirs ⇒ Object (readonly)
Returns the value of attribute reldirs.
4 5 6 |
# File 'lib/qrpm/lexer.rb', line 4 def reldirs @reldirs end |
Class Method Details
.load_yaml(file) ⇒ Object
Is actually a kind of lexer
12 13 14 15 |
# File 'lib/qrpm/lexer.rb', line 12 def self.load_yaml(file) # Is actually a kind of lexer text = IO.read(file).sub(/^__END__.*/m, "") YAML.load(text) end |
Instance Method Details
#lex(file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qrpm/lexer.rb', line 17 def lex(file) yaml = {} source = IO.read(file).sub(/^__END__.*/m, "") YAML.load(source).each { |k,v| if k == "include" includes = v.is_a?(String) ? [v] : v includes.each { |f| Lexer.load_yaml(search f).each { |k,v| yaml[k] = v } } else yaml[k] = v end } yaml end |
#search(file) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/qrpm/lexer.rb', line 31 def search(file) case file when /^\.\.\/(.*)/; reldirs.map { |d| "#{d}/../#$1" }.find { |f| File.exist? f } when /^\.\/(.*)/; reldirs.map { |d| "#{d}/#$1" }.find { |f| File.exist? f } when /^\//; File.exist?(file) && file else absdirs.map { |d| "#{d}/#{file}" }.find { |f| File.exist? f } end or raise Error, "Can't find #{file}" end |