class HaveAPI::Fs::Components::ActionExecEdit
Public Class Methods
new(action_dir)
click to toggle source
Calls superclass method
# File lib/haveapi/fs/components/action_exec_edit.rb, line 5 def initialize(action_dir) super() @action_dir = action_dir end
Public Instance Methods
header()
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 67 def header <<END # This file is in YAML format. Lines beginning with a hash (#) are comments and # are ignored. The action will be executed once this file is saved and closed. # The success of this operation can be later checked in # actions/#{@action_dir.action.name}/status. # # Only required parameters that need to be set are uncommented by default. # Parameters that are not specified when this file is closed will not be sent # to the API. # # To cancel the operation, either do not save the file or save it empty. END end
read()
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 14 def read ret = header + "\n" @action_dir.action.input_params.each do |name, p| param_file = @action_dir.find(:input).find(name) if param_file.set? v = param_file.new_value elsif p[:default].nil? v = nil else v = p[:default] end ret += "# #{p[:label]}; #{p[:type]}\n" ret += "# #{p[:description]}\n" ret += "# Defaults to '#{p[:default]}'\n" unless p[:default].nil? if p[:required] || param_file.set? ret += "#{name}: #{v}" else ret += "##{name}: #{v}" end ret += "\n\n" end ret end
save()
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 86 def save @action_dir.exec end
save?(data)
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 82 def save?(data) true end
writable?()
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 10 def writable? true end
write(str)
click to toggle source
# File lib/haveapi/fs/components/action_exec_edit.rb, line 47 def write(str) return if str.strip.empty? data = YAML.load(str) raise Errno::EIO, 'invalid yaml document' unless data.is_a?(::Hash) return unless save?(data) params = @action_dir.action.input_params data.each do |k, v| p = @action_dir.find(:input).find(k.to_sym) next if p.nil? # Type coercion is done later by the client during action call p.write_safe(v) end save end