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
-
.handles?(object) ⇒ Boolean
Returns
trueif this package handler canwrapandunwrapthe given object,falseotherwise. -
.unwrap(hash) ⇒ Object
Unwraps a generic hash into a newly instanced System.
-
.wrap(system) ⇒ Object
Wraps the given System into a generic hash.
Class Method Details
.handles?(object) ⇒ Boolean
Returns true if this package handler can wrap and unwrap the given object, false otherwise.
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.(*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., :type => system.class } end |