module Peregrine::Handlers::SystemPackage

This module provides methods which allow System objects to be wrapped and unwrapped for use by an instance of the Package class.

Public Class Methods

handles?(object) click to toggle source

Returns true if this package handler can wrap and unwrap the given object, false otherwise.

# File lib/peregrine/handlers/system_package.rb, line 8
def self.handles?(object)
  if object.class == Class
    object.ancestors.include?(Peregrine::System)
  else
    object.kind_of?(Peregrine::System)
  end
end
unwrap(hash) click to toggle source

Unwraps a generic hash into a newly instanced System.

# File lib/peregrine/handlers/system_package.rb, line 26
def self.unwrap(hash)
  return nil unless handles?(hash[:type])
  hash[:type].new do |system|
    system.name = hash[:name]
    system.disable unless hash[:status]
    system.add_tags(*hash[:tags])
  end
end
wrap(system) click to toggle source

Wraps the given System into a generic hash.

# File lib/peregrine/handlers/system_package.rb, line 17
def self.wrap(system)
  return nil unless handles?(system)
  { :name   => system.name,
    :status => system.enabled?,
    :tags   => system.tags,
    :type   => system.class }
end