Class: Itamae::Resource::GemPackage
- Inherits:
-
Base
- Object
- Base
- Itamae::Resource::GemPackage
show all
- Defined in:
- lib/itamae/resource/gem_package.rb
Instance Attribute Summary
Attributes inherited from Base
#attributes, #current_attributes, #notifications, #recipe, #resource_name, #subscriptions, #updated
Instance Method Summary
collapse
Methods inherited from Base
#action_nothing, define_attribute, inherited, #initialize, #resource_type, #run
Instance Method Details
#action_install(action_options) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/itamae/resource/gem_package.rb', line 33
def action_install(action_options)
if current.installed
if attributes.version && current.version != attributes.version
install!
updated!
end
else
install!
updated!
end
end
|
#action_upgrade(action_options) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/itamae/resource/gem_package.rb', line 45
def action_upgrade(action_options)
return if current.installed && attributes.version && current.version == attributes.version
install!
updated!
end
|
#install! ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/itamae/resource/gem_package.rb', line 66
def install!
cmd = [attributes.gem_binary, 'install']
if attributes.version
cmd << '-v' << attributes.version
end
if attributes.source
cmd << '--source' << attributes.source
end
cmd << attributes.package_name
run_command(cmd)
end
|
#installed_gems ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/itamae/resource/gem_package.rb', line 52
def installed_gems
gems = []
run_command([attributes.gem_binary, 'list', '-l']).stdout.each_line do |line|
if /\A([^ ]+) \(([^\)]+)\)\z/ =~ line.strip
name = $1
versions = $2.split(', ')
gems << {name: name, versions: versions}
end
end
gems
rescue Backend::CommandExecutionError
[]
end
|
#pre_action ⇒ Object
12
13
14
15
16
17
|
# File 'lib/itamae/resource/gem_package.rb', line 12
def pre_action
case @current_action
when :install
attributes.installed = true
end
end
|
#set_current_attributes ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/itamae/resource/gem_package.rb', line 19
def set_current_attributes
installed = installed_gems.find {|g| g[:name] == attributes.package_name }
current.installed = !!installed
if current.installed
versions = installed[:versions]
if versions.include?(attributes.version)
current.version = attributes.version
else
current.version = versions.first
end
end
end
|