Module: Animoto::Support::StandardEnvelope

Included in:
Resources::Base
Defined in:
lib/animoto/support/standard_envelope.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.find_class_for(envelope) ⇒ Class?

Scans the structure of a standard envelope for the ‘payload key’ and tries to find the matching class for that key. Returns nil if the class isn’t found (instead of, say, raising a NameError).

Parameters:

  • envelope (Hash{String=>Object})

    a ‘standard envelope’ hash

Returns:

  • (Class, nil)

    the class, or nil if either the payload key or the class couldn’t be found



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/animoto/support/standard_envelope.rb', line 24

def self.find_class_for envelope
  if payload_key = unpack_base_payload(envelope).keys.first
    klass_name = payload_key.camelize
    if /(?:Job|Callback)$/ === klass_name
      klass_name.sub!(/(?:Job|Callback)$/, '')
      Animoto::Resources::Jobs::const_get(klass_name) if Animoto::Resources::Jobs::const_defined?(klass_name)
    else
      Animoto::Resources::const_get(klass_name) if Animoto::Resources::const_defined?(klass_name)
    end
  end
rescue NameError
  nil
end

.included(base) ⇒ void

This method returns an undefined value.

When included into a class, also extends ClassMethods, inludes InstanceMethods, and includes Support::ContentType

Parameters:

  • base (Module)

    the module this is being included into



10
11
12
13
14
15
16
# File 'lib/animoto/support/standard_envelope.rb', line 10

def self.included base
  base.class_eval {
    include Animoto::Support::StandardEnvelope::InstanceMethods
    extend Animoto::Support::StandardEnvelope::ClassMethods
    include Animoto::Support::ContentType
  }
end