Class: Panda::Scope

Inherits:
Proxy
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/panda/proxies/scope.rb

Direct Known Subclasses

EncodingScope, ProfileScope, VideoScope

Instance Attribute Summary

Attributes inherited from Proxy

#klass, #parent

Instance Method Summary collapse

Methods inherited from Proxy

#cloud, #sti_name

Methods included from CloudConnection

#connection

Methods included from Finders::FindOne

#find, #find_object_by_path

Methods included from Finders::FindMany

#find_by

Methods included from Router::ClassMethods

#build_hash_many_path, #create_rest_url, #many_path, #match, #one_path, #resource_path

Constructor Details

#initialize(parent, klass) ⇒ Scope

Returns a new instance of Scope.



16
17
18
19
20
21
# File 'lib/panda/proxies/scope.rb', line 16

def initialize(parent, klass)
  super

  initialize_scope_attributes
  initialize_scopes
end

Dynamic Method Handling

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

Instance Method Details

#all(attributes = {}) ⇒ Object



46
47
48
49
# File 'lib/panda/proxies/scope.rb', line 46

def all(attributes={})
  @scoped_attributes.merge!(attributes)
  trigger_request
end

#create(attributes) ⇒ Object



36
37
38
39
# File 'lib/panda/proxies/scope.rb', line 36

def create(attributes)
  scoped_attrs = attributes.merge(@scoped_attributes)
  super(scoped_attrs)
end

#create!(attributes) ⇒ Object



41
42
43
44
# File 'lib/panda/proxies/scope.rb', line 41

def create!(attributes)
  scoped_attrs = attributes.merge(@scoped_attributes)
  super(scoped_attrs)
end

#find_by_path(url, map = {}) ⇒ Object

Overide the function to set the cloud_id as the same as the scope



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/panda/proxies/scope.rb', line 24

def find_by_path(url, map={})
  object = find_object_by_path(url, map)

  if object.is_a?(Array)
    object.map{|o| klass.new(o.merge('cloud_id' => cloud.id))}
  elsif object['id']
    klass.new(object.merge('cloud_id' => cloud.id))
  else
    raise APIError.new(object)
  end
end

#non_delegate_methodsObject



12
13
14
# File 'lib/panda/proxies/scope.rb', line 12

def non_delegate_methods
   [:nil?, :send, :object_id, :respond_to?, :class, :find, :find_by, :create, :create!, :all, :cloud, :connection]
end

#reloadObject



51
52
53
# File 'lib/panda/proxies/scope.rb', line 51

def reload
  @found = trigger_request
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/panda/proxies/scope.rb', line 7

def respond_to?(method)
  scoped_methods = [].methods.map{|i| i.to_sym} - non_delegate_methods + [:reload, :non_delegate_methods]
  !(scoped_methods).include?(method.to_sym)
end