Class: Panda::Resource
- Extended by:
- CloudConnection, Finders::FindMany
- Includes:
- Associations, Builders, CloudConnection
- Defined in:
- lib/panda/resources/resource.rb
Constant Summary
Constants included from Router
Panda::Router::DEFAULT_FORMAT, Panda::Router::VAR_PATTERN
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .cloud ⇒ Object
-
.method_missing(method_symbol, *args, &block) ⇒ Object
delegate to the scope if the method exists.
Instance Method Summary collapse
- #cloud ⇒ Object
- #create ⇒ Object
- #create! ⇒ Object
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
- #reload ⇒ Object
Methods included from CloudConnection
Methods included from Finders::FindMany
Methods included from Associations
Methods included from Builders
Methods inherited from Base
#changed?, #delete, end_class_name, id, #id, #id=, #new?, #to_json
Methods included from Router
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Panda::Base
Class Method Details
.cloud ⇒ Object
16 17 18 |
# File 'lib/panda/resources/resource.rb', line 16 def cloud Panda.cloud end |
.method_missing(method_symbol, *args, &block) ⇒ Object
delegate to the scope if the method exists
21 22 23 24 25 26 27 28 |
# File 'lib/panda/resources/resource.rb', line 21 def method_missing(method_symbol, *args, &block) scope = Panda::const_get("#{end_class_name}Scope").new(self) if scope.respond_to?(method_symbol) scope.send(method_symbol, *args, &block) else super end end |
Instance Method Details
#cloud ⇒ Object
32 33 34 |
# File 'lib/panda/resources/resource.rb', line 32 def cloud Panda.clouds[cloud_id] end |
#create ⇒ Object
36 37 38 39 40 |
# File 'lib/panda/resources/resource.rb', line 36 def create raise "Can't create attribute. Already have an id=#{attributes['id']}" if attributes['id'] response = connection.post(object_url_map(self.class.many_path), attributes) load_response(response) ? (@changed_attributes = {}; true) : false end |
#create! ⇒ Object
42 43 44 |
# File 'lib/panda/resources/resource.rb', line 42 def create! create || errors.last.raise! end |
#reload ⇒ Object
46 47 48 49 50 |
# File 'lib/panda/resources/resource.rb', line 46 def reload perform_reload("cloud_id" => cloud_id) reset_associations self end |