Class: Alain::Cargo
- Inherits:
-
Object
- Object
- Alain::Cargo
- Defined in:
- lib/alain/cargo.rb
Instance Method Summary collapse
- #add_dependencies(server_conf: false) ⇒ Object
- #crate_name ⇒ Object
-
#initialize(dir = '.') ⇒ Cargo
constructor
A new instance of Cargo.
Constructor Details
#initialize(dir = '.') ⇒ Cargo
Returns a new instance of Cargo.
8 9 10 11 12 13 14 15 |
# File 'lib/alain/cargo.rb', line 8 def initialize(dir = '.') toml = Pathname(dir) / 'Cargo.toml' unless File.exist? toml STDERR.puts "./Cargo.toml not found. 'cargo init' first." exit 1 end @cargo = Tomlrb.load_file toml end |
Instance Method Details
#add_dependencies(server_conf: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/alain/cargo.rb', line 17 def add_dependencies(server_conf: false) toml = Pathname('.') / 'Cargo.toml' origin = File.read toml File.open(toml, 'w') do |f| origin.each_line do |line| if /^\[dependencies\]/.match(line) f.puts line dependencies(server_conf).each do |k, entry| next if @cargo['dependencies'].keys.include? k f.puts entry end elsif /^\[build-dependencies\]/.match(line) f.puts line build_dependencies.each do |k, entry| next if @cargo['build-dependencies'].keys.include? k f.puts entry end else f.puts line end end unless @cargo['build-dependencies'] f.puts '[build-dependencies]' f.puts build_dependencies.values.join("\n") end end end |
#crate_name ⇒ Object
45 46 47 |
# File 'lib/alain/cargo.rb', line 45 def crate_name @cargo.dig('package', 'name').gsub(/-/, '_') end |