module Peregrine::Handlers::ComponentPackage

This module provides methods which allow Component 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/component_package.rb, line 8
def self.handles?(object)
  if object.class == Class
    object.ancestors.include?(Peregrine::Component)
  else
    object.kind_of?(Peregrine::Component)
  end
end
unwrap(hash) click to toggle source

Unwraps a generic hash into a newly instanced Component.

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

Wraps the given Component into a generic hash.

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