Class: DeltaCloud::Operation::GET
- Inherits:
-
Object
- Object
- DeltaCloud::Operation::GET
- Defined in:
- lib/deltacloud-cli.rb
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Instance Method Summary collapse
-
#initialize(operation, resource, options) ⇒ GET
constructor
A new instance of GET.
- #to_s ⇒ Object
Constructor Details
#initialize(operation, resource, options) ⇒ GET
Returns a new instance of GET.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/deltacloud-cli.rb', line 123 def initialize(operation, resource, ) @operation = operation begin if operation == :list @collection = DeltaCloud::Operation::client.send(:"#{resource}") end if operation == :get @collection = [DeltaCloud::Operation::client.send(:"#{resource}", .strip)].compact end rescue NoMethodError ap "ERROR: Unknown resource #{resource}. Type 'resources' to list all resources" end return self end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
121 122 123 |
# File 'lib/deltacloud-cli.rb', line 121 def operation @operation end |
Instance Method Details
#to_s ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/deltacloud-cli.rb', line 138 def to_s return '0 items returned' if not @collection return '0 items returned' if @collection.empty? output = @collection.collect do |item| base = { :id => item.id, :name => item.name, } base.merge!(:state => item.state) if item.respond_to?(:state) base.merge!(:description => item.description) if item.respond_to?(:description) base end return output if @operation == :list return output.first if @operation == :get end |