lib/milc/gcloud/resource.rb in milc-0.1.0 vs lib/milc/gcloud/resource.rb in milc-0.1.1

- old
+ new

@@ -1,10 +1,11 @@ # coding: utf-8 require "milc/gcloud" require "yaml" +require "json" require 'active_support/core_ext/string/inflections' module Milc module Gcloud @@ -14,18 +15,19 @@ @command_defs ||= YAML.load_file(File.expand_path("../commands.yml", __FILE__)) end def command_def_for(service, resource) c = command_defs - s = c[service] or raise "service #{service.inspect} not found in #{commands.keys.join(', ')}" - s[resource] or raise "resource #{resource.inspect} not found in #{s.keys.join(' ')} of #{service.inspect}" + s = c[service.to_s] or raise "service #{service.inspect} not found in #{c.keys.join(', ')}" + s[resource.to_s] or raise "resource #{resource.inspect} not found in #{s.keys.join(' ')} of #{service.inspect}" end def lookup(project, service, resource) Milc.logger.debug("=" * 100) Milc.logger.debug("project: #{project}, service: #{service}, resource: #{resource}") - + service = service.to_s + resource = resource.to_s command_def = command_def_for(service, resource) result = new(project, service, resource, command_def['commands']) service_module = Milc::Gcloud.const_get(service.classify) m = resource.gsub(/-/, '_').camelize.to_sym if service_module.constants.include?(m) @@ -130,10 +132,10 @@ raise "Resource not found #{service} #{resource} #{name}" unless r return r if compare(attrs, r) call_update(cmd_args, attrs, &block) end - def delete(cmd_args, attrs, &block) + def delete(cmd_args, attrs = {}, &block) raise_if_invalid(:delete) name, args = *cmd_args.split(/\s+/, 2) r = find(name) return nil unless r call_action(:delete, cmd_args, attrs, &block)