Module: Baltix::Loader::Rookbook
- Included in:
- Source::Gem
- Defined in:
- lib/baltix/loader/rookbook.rb
Overview
Rookbook based gemspec detection module
Instance Method Summary collapse
Instance Method Details
#rookbook(propfile) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/baltix/loader/rookbook.rb', line 4 def rookbook propfile dir = File.dirname(propfile) props = IO.read(propfile) .split("\n") .map do |line| /^(?<key>[^:]+):\s*(?<value>.*)$/ =~ line [ key, value ] end .to_h specfile = Dir.glob(File.join(dir, '**', '*.gemspec')).first # fix specfile oldspec = IO.read(specfile) newspec = oldspec.split("\n").map do |x| props.reduce(x) { |x, (key, value)| x.gsub(/\$#{key}[: ]*\$/i, value) } end if oldspec != newspec File.open(specfile, 'w+') {|file| file.puts newspec } end end |