class Itamae::Plugin::Resource::Snappy

Public Instance Methods

action_install(_action_options) click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 25
def action_install(_action_options)
  return if current.installed
  install!
  updated!
end
action_remove(_action_options) click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 31
def action_remove(_action_options)
  remove! if current.installed
end
install!() click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 48
def install!
  cmd = ['snap', 'install', *Array(attributes.options)]
  cmd << '--classic' if attributes.classic
  cmd << attributes.package_name

  run_command(cmd)
end
installed_snaps() click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 35
def installed_snaps
  snaps = []
  run_command(['snap', 'list']).stdout.each_line do |line|
    if /\A(\S+)\s+(\S+)/ =~ line.strip
      name, _version, _rev, _developer, _notes = $1
      snaps << name if name != 'Name'
    end
  end
  snaps
rescue Backend::CommandExecutionError
  []
end
pre_action() click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 12
def pre_action
  case @current_action
    when :install
      attributes.installed = true
    when :remove
      attributes.installed = false
  end
end
remove!() click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 56
def remove!
  cmd = ['snap', 'remove']
  cmd << attributes.package_name

  run_command(cmd)
end
set_current_attributes() click to toggle source
# File lib/itamae/plugin/resource/snappy.rb, line 21
def set_current_attributes
  current.installed = installed_snaps.include?(attributes.package_name)
end