Module: Peregrine::Handlers::ComponentPackage
- Defined in:
- lib/peregrine/handlers/component_package.rb
Overview
This module provides methods which allow Component 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 Component.
-
.wrap(component) ⇒ Object
Wraps the given Component 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/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) ⇒ Object
Unwraps a generic hash into a newly instanced Component.
25 26 27 28 29 30 31 |
# 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.(*hash[:tags]) end end |
.wrap(component) ⇒ Object
Wraps the given Component into a generic hash.
17 18 19 20 21 22 |
# File 'lib/peregrine/handlers/component_package.rb', line 17 def self.wrap(component) return nil unless handles?(component) { :name => component.name, :tags => component., :type => component.class } end |