Class: Panda::Resource

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

Direct Known Subclasses

Encoding, Profile, Video

Constant Summary

Constants included from Router

Panda::Router::VAR_PATTERN

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CloudConnection

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/panda/resources/resource.rb', line 7

def initialize(attributes={})
  super(attributes)
  @attributes['cloud_id'] ||= Panda.cloud.id
end

Dynamic Method Handling

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

Class Method Details

.cloudObject



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

def cloud
  Panda.cloud
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/panda/resources/resource.rb', line 20

def method_missing(method_symbol, *args, &block)
  scope = Panda::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

#cloudObject



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

def cloud
  Panda.clouds[cloud_id]
end

#reloadObject



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

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