Module: DeltacloudVM::Client::Helpers::Model
- Included in:
- Base, Connection, ErrorResponse
- Defined in:
- lib/deltacloud_vm/client/helpers/model_helper.rb
Instance Method Summary collapse
-
#error(name = nil) ⇒ Object
Syntax sugar method for retrieving various Client exception classes.
-
#from_collection(model_name, collection_body) ⇒ Object
Checks if current @connection support
model_name
and then convert HTTP response to a Ruby model. -
#from_resource(model_name, resource_body) ⇒ Object
Check if the collection for given model is supported in current @connection and then parse/convert resource XML to a Ruby class.
-
#model(name) ⇒ Object
Retrieve the class straight from DeltacloudVM::Client model.
Instance Method Details
#error(name = nil) ⇒ Object
Syntax sugar method for retrieving various Client exception classes.
-
name -> Exception class name in underscore
NOTE: If name is ‘nil’ the default Error exception
will be returned
40 41 42 |
# File 'lib/deltacloud_vm/client/helpers/model_helper.rb', line 40 def error(name=nil) model(name || :error) end |
#from_collection(model_name, collection_body) ⇒ Object
Checks if current @connection support model_name
and then convert HTTP response to a Ruby model
-
model_name -> A class name in underscore form
-
collection_body -> HTTP body of collection
50 51 52 53 54 55 56 |
# File 'lib/deltacloud_vm/client/helpers/model_helper.rb', line 50 def from_collection(model_name, collection_body) must_support!(model_name) model(model_name.to_s.singularize).from_collection( self, collection_body ) end |
#from_resource(model_name, resource_body) ⇒ Object
Check if the collection for given model is supported in current @connection and then parse/convert resource XML to a Ruby class
62 63 64 65 |
# File 'lib/deltacloud_vm/client/helpers/model_helper.rb', line 62 def from_resource(model_name, resource_body) must_support!(model_name.to_s.pluralize) model(model_name).convert(self, resource_body) end |
#model(name) ⇒ Object
Retrieve the class straight from DeltacloudVM::Client model.
-name -> A class name in underscore form (:storage_volume)
25 26 27 28 29 30 |
# File 'lib/deltacloud_vm/client/helpers/model_helper.rb', line 25 def model(name) if name.nil? or (!name.nil? and name.empty?) raise error.new("The model name can't be blank") end DeltacloudVM::Client.const_get(name.to_s.camelize) end |