Class: Bundly::CLI
- Inherits:
-
Thor
- Object
- Thor
- Bundly::CLI
- Defined in:
- lib/bundly/cli.rb
Instance Method Summary collapse
Instance Method Details
#gem(gem, *params) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bundly/cli.rb', line 42 def gem(gem, *params) yaml_path = Pathname([:yaml]) content = YAML.load(yaml_path.read) if content.is_a?(Array) gem_hash = content.find {|hash| hash["name"] == gem } if gem_hash params.map {|param| param.split(/=/, 2) }.each do |(key, value)| if value.size > 0 gem_hash[key] = value else gem_hash.delete key end end else puts "Could not find gem: #{gem}" end end yaml_path.write(YAML.dump(content)) end |
#setup ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bundly/cli.rb', line 9 def setup template = Pathname(__dir__) + "template.rb.erb" init_script = Pathname([:init]) unless init_script.parent.directory? puts "No directory for init script: #{init_script}" puts "> mkdir #{init_script.parent}" exit end init_script.open("w") do |io| io.write Erubis::Eruby.new(template.read).result end yaml_path = Pathname([:yaml]) yaml_path.write("") unless yaml_path.file? puts "1. Add the following line in your Gemfile to load gems from #{yaml_path}:" puts puts "require_relative '#{init_script}'" puts "gems File.join(__dir__, '#{yaml_path}')" puts puts "2. Declare your dependencies in #{yaml_path} like:" puts puts "- name: thor" puts " version: ~> 0.1.0" puts " git: https://github.com/rails/rails.git" puts " branch: foobarbaz" puts " tag: 9edd6f54315fbf29bdce4c662329f620ded0badf" puts end |