Module: Transit::Deliverable::ClassMethods

Defined in:
lib/transit/deliverable.rb

Overview

Class level methods and functionality

Instance Method Summary (collapse)

Instance Method Details

- (Object) deliver_as(type, options = {})

Configures attributes and deliverable specific methods for the calling model.

Parameters:

  • type (Symbol, String)

    The type of deliverable. Each deliverable type is specified as a Transit::Definition

  • options (Hash) (defaults to: {})

    Any deliverable specific options



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/transit/deliverable.rb', line 59

def deliver_as(type, options = {})
  
  include Transit::Definition::Base
  
  self.delivery_options ||= Transit::Deliverable::DeliveryOptions.new(options.reverse_merge!(:translate => Transit.config.translate))

  self.delivers_as = type
  self.delivery_options.merge!(options)

  self.has_translation_support = !!self.delivery_options.translate
  
  unless Transit::Definition.const_defined?(type.to_s.classify)
    raise Transit::Definition::MissingDefinitionError
  end
  
  include Transit::Definition.const_get(type.to_s.classify)
  
  # register the deliverable class
  delivery = type.to_s.classify
  Transit.deliverables[delivery] ||= []
  Transit.deliverables[delivery] |= [self.name.to_s]
  
  Transit.run_definition_hooks(:#{type.to_s}", self)
  
end