Class: Bling

Inherits:
Object
  • Object
show all
Defined in:
lib/bling/bling.rb

Instance Method Summary collapse

Constructor Details

#initialize(bling_file = ".gems") ⇒ Bling

Returns a new instance of Bling.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/bling/bling.rb', line 5

def initialize(bling_file = ".gems")
	raise ArgumentError, "bling file not found" unless File.exists?(bling_file)
	@yaml = YAML::load(ERB.new(File.read(bling_file)).result)
	
end

Instance Method Details

#gem_string(gem, version = nil) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/bling/bling.rb', line 18

def gem_string(gem, version = nil)
	if version
		gem.to_s + " [#{version}]"
	else
		gem.to_s
	end
end

#install_gems(env = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bling/bling.rb', line 36

def install_gems(env = nil)
	only_if_present = lambda{|pre, val| val.to_s.empty? ? "" : " #{pre}#{val}"}
	gem_installed = false
	each_gem_for(env) do |entry|
		begin
			version = only_if_present.call('-v=', entry['version'].to_s.gsub(/[=~<>]/, ''))
			source = only_if_present.call('--source=', entry['source'])
			gem *([entry['name'], entry['version'].to_s].compact)
		rescue Gem::LoadError
			gem_installed = true
			$stdout.puts "installing #{entry['name']} #{version}"
			`gem install #{entry['name']} #{version} #{source} ` unless ENV['PRACTICE']
		end
	end
	$stdout.puts "nothing to install!" unless gem_installed
end

#list_gems(env = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/bling/bling.rb', line 26

def list_gems(env = nil)
	lines = []
	self.each_gem_for(env) do |entry|
		line = gem_string(entry['name'], entry['version'])
		lines << line
		$stdout.puts line
	end
	lines
end

#require_env(env = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/bling/bling.rb', line 11

def require_env(env = nil)
	self.each_gem_for(env) do |entry|
 		gem *([entry['name'], entry['version']].compact)
 		require entry['lib'] || entry['name']
	end
end