Sha256: 48361c32da343a6fb2137dca317a5fa19a45d8e14ea3c2f11e5e918e5a5fc8d4

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

# Converts appliances into events
#
# @author Michal Kimle
class Nifty::Event::Converter
  # Converts appliance into event
  #
  # @param [Cloud::Appliance::Descriptor::Appliance] appliance
  # @param [Nifty::Backend] backend
  # @param [Nifty::TransferMethod] transfer_method
  # @param [Hash] parameters
  # @raise [Nifty::Errors::Event::ConverterError] when something goes wrong while conversion
  # @return [Nifty::Event] description of returned object
  def self.convert_appliance(appliance, backend, transfer_method, parameters)
    events_module = "Nifty::Events::#{backend.name.demodulize}".constantize

    logger.debug "Converting appliance #{appliance.inspect}"
    event_type = "#{appliance.action}_event".camelize

    fail Nifty::Errors::Event::ConverterError, "No such event type for action #{appliance.action.inspect}" unless events_module.constants.include?(event_type.to_sym)
    event_class = events_module.const_get(event_type)

    fail Nifty::Errors::Event::ConverterError, "Class #{event_class.inspect} doesn't represent an event" unless (event_class.respond_to?('event?') && event_class.event? && event_class.public_instance_methods.include?(:run))

    event = backend.create_event(event_class, appliance, transfer_method, parameters)
    logger.debug "Converted event: #{event.inspect}"

    event
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
nifty-0.2.12 lib/nifty/event/converter.rb
nifty-0.2.11 lib/nifty/event/converter.rb
nifty-0.2.10 lib/nifty/event/converter.rb
nifty-0.2.9 lib/nifty/event/converter.rb
nifty-0.2.8 lib/nifty/event/converter.rb
nifty-0.2.7 lib/nifty/event/converter.rb
nifty-0.2.6 lib/nifty/event/converter.rb
nifty-0.2.5 lib/nifty/event/converter.rb
nifty-0.2.4 lib/nifty/event/converter.rb
nifty-0.2.3 lib/nifty/event/converter.rb
nifty-0.2.2 lib/nifty/event/converter.rb