# File lib/deltacloud/drivers/mock/mock_client.rb, line 23 def initialize(storage_root) @storage_root = storage_root @collections = [] if ! File::directory?(@storage_root) FileUtils::rm_rf(@storage_root) FileUtils::mkdir_p(@storage_root) data = Dir[File::join(File::dirname(__FILE__), "data", "*")] FileUtils::cp_r(data, @storage_root) end end
Return the object with id id of class klass from the collection derived from the classes name
# File lib/deltacloud/drivers/mock/mock_client.rb, line 73 def build(klass, id) klass.new(load(collection_name(klass), id)) end
Return an array of model objects of the resources in the collection corresponding to class. The name of the collection is derived from the name of the class
# File lib/deltacloud/drivers/mock/mock_client.rb, line 85 def build_all(klass) load_all(collection_name(klass)).map { |hash| klass.new(hash) } end
# File lib/deltacloud/drivers/mock/mock_client.rb, line 89 def destroy(collection, id) fname = file(collection, id) FileUtils.rm(fname) if File::exists?(fname) end
# File lib/deltacloud/drivers/mock/mock_client.rb, line 35 def dir(collection) result = File::join(@storage_root, collection.to_s) unless @collections.include?(collection) FileUtils::mkdir_p(result) unless File::directory?(result) @collections << collection end result end
# File lib/deltacloud/drivers/mock/mock_client.rb, line 44 def file(collection, id) File::join(dir(collection), "#{id}.yml") end
# File lib/deltacloud/drivers/mock/mock_client.rb, line 48 def files(collection) Dir[File::join(dir(collection), "*.yml")] end
# File lib/deltacloud/drivers/mock/mock_client.rb, line 57 def load(collection, id) fname = file(collection, id) begin YAML.load(File.read(fname)) rescue Errno::ENOENT nil end end
Return an array of hashes of all the resources in the collection
# File lib/deltacloud/drivers/mock/mock_client.rb, line 78 def load_all(collection) members(collection).map { |id| load(collection, id) } end
Generated with the Darkfish Rdoc Generator 2.