class Locd::CLI::Command::Project
Public Instance Methods
load()
click to toggle source
# File lib/locd/cli/command/project.rb, line 35 def load file_path = options[:file].to_pn.expand_path unless file_path.file? raise "Definition file not found at `#{ file_path }`" end defs = YAML.load( file_path.read ).with_indifferent_access t.hash_( keys: t.in(%w{agents sites jobs}), ).check! defs { agents: Locd::Agent, sites: Locd::Agent::Site, jobs: Locd::Agent::Job, }.each do |key, agent_class| if defs.key? key logger.info "Adding or updating #{ key }..." defs[key].each do |label, values| logger.info payload: { values: values, options: values.to_options, } method, agent = agent_class.add_or_update \ label: label, **values. map { |key, value| key = key.gsub '-', '_' if key == 'cmd_template' value = value.squish end [ key, value ] }. to_h. to_options action = t.match method, :add, 'added', :update, 'updated' logger.info "Agent `#{ label }` #{ action }" end # each label, values end # if defs.key? key end # each key, agent_class end