Class: Itamae::Resource::Package

Inherits:
Base
  • Object
show all
Defined in:
lib/itamae/resource/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, #do_not_run_because_of_not_if?, #do_not_run_because_of_only_if?, inherited, #initialize, #resource_type, #run

Constructor Details

This class inherits a constructor from Itamae::Resource::Base

Instance Method Details

#action_install(action_options) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/itamae/resource/package.rb', line 26

def action_install(action_options)
  return if !attributes.version && current.installed

  unless run_specinfra(:check_package_is_installed, attributes.name, attributes.version)
    run_specinfra(:install_package, attributes.name, attributes.version, attributes.options)
    updated!
  end
end

#action_remove(action_options) ⇒ Object



35
36
37
38
39
40
# File 'lib/itamae/resource/package.rb', line 35

def action_remove(action_options)
  if current.installed
    run_specinfra(:remove_package, attributes.name, attributes.options)
    updated!
  end
end

#pre_actionObject



9
10
11
12
13
14
15
16
# File 'lib/itamae/resource/package.rb', line 9

def pre_action
  case @current_action
  when :install
    attributes.installed = true
  when :remove
    attributes.installed = false
  end
end

#set_current_attributesObject



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

def set_current_attributes
  current.installed = run_specinfra(:check_package_is_installed, attributes.name)

  if current.installed
    current.version = run_specinfra(:get_package_version, attributes.name).stdout.strip
  end
end