class DTK::Client::CLI::Command::Service::SetAttributeHelper
Attributes
service_instance[R]
service_instance_dir[R]
Public Class Methods
new(service_instance, service_instance_dir)
click to toggle source
# File lib/cli/command/service/set_attribute.rb, line 64 def initialize(service_instance, service_instance_dir) @service_instance = service_instance @service_instance_dir = service_instance_dir end
Public Instance Methods
get_name_value_pairs_from_yaml_file(options)
click to toggle source
# File lib/cli/command/service/set_attribute.rb, line 88 def get_name_value_pairs_from_yaml_file(options) unless ruby_obj = get_yaml_from_file?(options) raise Error::Usage, "If NAME argument is not given then -f option must be given to specify a value" end # check that gile is form #attributes: # name1: val1 # ... unless ruby_obj.kind_of?(::Hash) and ruby_obj.size == 1 and ruby_obj.keys.first == 'attributes' raise Error::Usage, "If NAME argument is not given, the parameter file content must be YAML hash starting with key 'attributes'" end name_value_pairs = ruby_obj['attributes'] unless name_value_pairs.kind_of?(::Hash) raise Error::Usage, "If NAME argument is not given, the parameter file content must be YAML hash with name/attribute values" end name_value_pairs.inject({}) do |h, (k, v)| value = case v when ::Hash, ::Array ::JSON.generate(v) else v end h.merge(k => value) end end
get_yaml_from_file?(cli_options)
click to toggle source
# File lib/cli/command/service/set_attribute.rb, line 81 def get_yaml_from_file?(cli_options) if param_file_path = cli_options[:f] param_file = check_and_return_file_content(param_file_path) yaml_to_ruby_obj(param_file, param_file_path) end end
set_single_attribute(attribute_name, attribute_value, opts = {})
click to toggle source
opts can haev keys
:encrypt
# File lib/cli/command/service/set_attribute.rb, line 71 def set_single_attribute(attribute_name, attribute_value, opts = {}) Operation::Service.set_attribute( :attribute_name => attribute_name, :attribute_value => attribute_value, :encrypt => opts[:encrypt], :service_instance => self.service_instance, :service_instance_dir => self.service_instance_dir ) end
Private Instance Methods
check_and_return_file_content(path)
click to toggle source
# File lib/cli/command/service/set_attribute.rb, line 118 def check_and_return_file_content(path) raise Error::Usage, "The file at path '#{path}' does not exist" unless File.file?(path) File.open(path).read end
yaml_to_ruby_obj(text, path)
click to toggle source
# File lib/cli/command/service/set_attribute.rb, line 123 def yaml_to_ruby_obj(text, path) begin ::YAML.load(text) rescue raise Error::Usage, "Content in file '#{path}' is ill-formed YAML" end end