Module: Fog::CloudSigma::CloudSigmaConnection::Mock
- Included in:
- Fog::Compute::CloudSigma::Mock
- Defined in:
- lib/fog/cloudsigma/connection.rb
Instance Method Summary collapse
- #mock_create(collection, status, data, key, defaults = {}, &clean_before_store) ⇒ Object
- #mock_delete(collection, status, key) ⇒ Object
- #mock_get(obj_or_collection, status, key = nil) ⇒ Object
- #mock_list(collection, status) ⇒ Object
- #mock_update(data, obj_or_collection, status, key, &clean_before_update) ⇒ Object
- #setup_connection(options) ⇒ Object
Instance Method Details
#mock_create(collection, status, data, key, defaults = {}, &clean_before_store) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/fog/cloudsigma/connection.rb', line 166 def mock_create(collection, status, data, key, defaults={}, &clean_before_store) data_with_defaults = data.merge(defaults) {|k, oldval, newval| oldval == nil ? newval: oldval} if clean_before_store cleaned_data = clean_before_store.call(data_with_defaults) else cleaned_data = data_with_defaults end # Encode and decode into JSON so that the result is the same as the one returned and parsed from the API final_data = Fog::JSON.decode(Fog::JSON.encode(cleaned_data)) self.data[collection][key] = final_data # dup so that stored data is different instance from response data response_data = final_data.dup response = Excon::Response.new response.body = {'objects' => [response_data]} response.status = status response end |
#mock_delete(collection, status, key) ⇒ Object
160 161 162 163 164 |
# File 'lib/fog/cloudsigma/connection.rb', line 160 def mock_delete(collection, status, key) self.data[collection].delete(key) Excon::Response.new(:body => '', :status => status) end |
#mock_get(obj_or_collection, status, key = nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/fog/cloudsigma/connection.rb', line 116 def mock_get(obj_or_collection, status, key=nil) data = self.data[obj_or_collection] if key data = data[key] unless data raise Fog::CloudSigma::Errors::NotFound.new("Object with uuid #{key} does not exist", 'notexist') end end Excon::Response.new(:body => Fog::JSON.decode(Fog::JSON.encode(data)), :status => status) end |
#mock_list(collection, status) ⇒ Object
128 129 130 131 132 |
# File 'lib/fog/cloudsigma/connection.rb', line 128 def mock_list(collection, status) data_array = self.data[collection].values Excon::Response.new(:body => {'objects' => data_array}, :status => status) end |
#mock_update(data, obj_or_collection, status, key, &clean_before_update) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/fog/cloudsigma/connection.rb', line 134 def mock_update(data, obj_or_collection, status, key, &clean_before_update) data = Fog::JSON.decode(Fog::JSON.encode(data)) if key unless self.data[obj_or_collection][key] raise Fog::CloudSigma::Errors::NotFound.new("Object with uuid #{key} does not exist", 'notexist') end if clean_before_update new_data = clean_before_update.call(self.data[obj_or_collection][key], data) else new_data = self.data[obj_or_collection][key].merge(data) end self.data[obj_or_collection][key] = new_data else if clean_before_update new_data = clean_before_update.call(self.data[obj_or_collection], data) else new_data = self.data[obj_or_collection].merge(data) end self.data[obj_or_collection] = new_data end Excon::Response.new(:body => Fog::JSON.decode(Fog::JSON.encode(new_data)), :status => status) end |
#setup_connection(options) ⇒ Object
111 112 113 114 |
# File 'lib/fog/cloudsigma/connection.rb', line 111 def setup_connection() @username = [:cloudsigma_username] @password = [:cloudsigma_password] end |