Class: TelestreamCloud::Resource

Inherits:
Base
  • Object
show all
Extended by:
FactoryConnection
Includes:
Associations, Destroyers, FactoryConnection
Defined in:
lib/telestream_cloud/resources/resource.rb

Direct Known Subclasses

Encoding, Profile, Video

Constant Summary

Constants included from Router

TelestreamCloud::Router::VAR_PATTERN

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FactoryConnection

connection

Methods included from Associations

included

Methods included from Destroyers

#delete, included

Methods inherited from Base

#changed?, #id, #id=, #inspect, #new?, sti_name, #to_json

Methods included from Finders

included

Methods included from Builders

#create, #create!, included

Methods included from Router

included, #replace_pattern_with_self_variables

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
# File 'lib/telestream_cloud/resources/resource.rb', line 7

def initialize(attributes={})
  super(attributes)
  @attributes['factory_id'] ||= TelestreamCloud.factory.id
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class TelestreamCloud::Base

Class Method Details

.factoryObject



15
16
17
# File 'lib/telestream_cloud/resources/resource.rb', line 15

def factory
  TelestreamCloud.factory
end

.method_missing(method_symbol, *args, &block) ⇒ Object

delegate to the scope if the method exists



20
21
22
23
24
25
26
27
# File 'lib/telestream_cloud/resources/resource.rb', line 20

def method_missing(method_symbol, *args, &block)
  scope = TelestreamCloud::const_get("#{sti_name}Scope").new(self)
  if scope.respond_to?(method_symbol)
     scope.send(method_symbol, *args, &block)
  else
    super
  end
end

Instance Method Details

#factoryObject



31
32
33
# File 'lib/telestream_cloud/resources/resource.rb', line 31

def factory
  TelestreamCloud.factories[factory_id]
end

#reloadObject



35
36
37
38
39
# File 'lib/telestream_cloud/resources/resource.rb', line 35

def reload
  perform_reload("factory_id" => factory_id)
  reset_associations
  self
end