Module: Require::Tasks
- Defined in:
- lib/require/tasks.rb
Class Method Summary collapse
- .has_gem?(name, version = nil) ⇒ Boolean
- .install_gem(name, version = nil) ⇒ Object
- .rm_pkg ⇒ Object
- .run(cmd) ⇒ Object
- .set(*types) ⇒ Object
Class Method Details
.has_gem?(name, version = nil) ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/require/tasks.rb', line 41 def self.has_gem?(name, version=nil) if !$GEM_LIST gems = {} `gem list --local`.each_line do |line| gems[$1.to_sym] = $2.split(/, /) if line =~ /^(.*) \(([^\)]*)\)$/ end $GEM_LIST = gems end if $GEM_LIST[name.to_sym] if version version = version.gsub("=",'') if $GEM_LIST[name.to_sym].include?(version) $stdout.puts "Gem: #{name}:#{version} already installed, skipping" return true end else $stdout.puts "Gem: #{name} already installed, skipping" return true end end false end |
.install_gem(name, version = nil) ⇒ Object
35 36 37 38 39 |
# File 'lib/require/tasks.rb', line 35 def self.install_gem(name, version = nil) unless has_gem?(name, version) run "gem install #{name}#{" -v '#{version}'" if version}" end end |
.rm_pkg ⇒ Object
23 24 25 26 27 |
# File 'lib/require/tasks.rb', line 23 def self.rm_pkg cmd = "rm -Rf pkg" $stdout.puts cmd system cmd end |
.run(cmd) ⇒ Object
29 30 31 32 33 |
# File 'lib/require/tasks.rb', line 29 def self.run(cmd) cmd = "#{'sudo ' if @@use_sudo}#{cmd}#{' --no-ri --no-rdoc' unless @@gen_docs}" $stdout.puts cmd system cmd end |
.set(*types) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/require/tasks.rb', line 4 def self.set(*types) if types.include?(:ask_docs) $stdout.puts "Generate documentation?" @@gen_docs = $stdin.gets.downcase[0..0] == 'y' elsif types.include?(:docs) @@gen_docs = true elsif types.include?(:no_docs) @@gen_docs = false end if types.include?(:ask_sudo) $stdout.puts "Use sudo?" @@use_sudo = $stdin.gets.downcase[0..0] == 'y' elsif types.include?(:sudo) @@use_sudo = true elsif types.include?(:no_sudo) @@use_sudo = false end end |