Module: Peregrine::Handlers::SystemPackage

Defined in:
lib/peregrine/handlers/system_package.rb

Overview

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

Class Method Summary collapse

Class Method Details

.handles?(object) ⇒ Boolean

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

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# 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) ⇒ Object

Unwraps a generic hash into a newly instanced System.



26
27
28
29
30
31
32
33
# 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) ⇒ Object

Wraps the given System into a generic hash.



17
18
19
20
21
22
23
# 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