Module: Travis::Tools::Completion
- Extended by:
- Completion
- Includes:
- FileUtils
- Included in:
- Completion
- Defined in:
- lib/travis/tools/completion.rb
Constant Summary collapse
- RCS =
['.zshrc', '.bashrc'].map { |f| File.(f, ENV['HOME']) }
Instance Method Summary collapse
- #cmp_file ⇒ Object
- #compile ⇒ Object
- #completion_installed? ⇒ Boolean
- #config_path ⇒ Object
- #install_completion ⇒ Object
- #update_completion ⇒ Object
Instance Method Details
#cmp_file ⇒ Object
17 18 19 |
# File 'lib/travis/tools/completion.rb', line 17 def cmp_file File.('travis.sh', config_path) end |
#compile ⇒ Object
46 47 48 49 50 51 |
# File 'lib/travis/tools/completion.rb', line 46 def compile commands = Travis::CLI.commands.sort_by { |c| c.command_name } template = Assets.read('travis.sh.erb') source = ERB.new(template).result(binding).gsub(/^ +\n/, '') File.write(Assets['travis.sh'], source) end |
#completion_installed? ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'lib/travis/tools/completion.rb', line 37 def completion_installed? source = "source " << config_path RCS.each do |file| next unless File.exist? file and File.writable? file return false unless File.read(file).include? source end true end |
#config_path ⇒ Object
13 14 15 |
# File 'lib/travis/tools/completion.rb', line 13 def config_path ENV.fetch('TRAVIS_CONFIG_PATH') { File.('.travis', ENV['HOME']) } end |
#install_completion ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/travis/tools/completion.rb', line 21 def install_completion update_completion source = "source " << cmp_file RCS.each do |file| next unless File.exist? file and File.writable? file next if File.read(file).include? source File.open(file, "a") { |f| f.puts("", "# added by travis gem", "[ -f #{cmp_file} ] && #{source}") } end end |
#update_completion ⇒ Object
32 33 34 35 |
# File 'lib/travis/tools/completion.rb', line 32 def update_completion mkdir_p(config_path) cp(Assets['travis.sh'], cmp_file) end |