class Lono::Importer::Params
Attributes
options[R]
Public Class Methods
new(template_path, params_path)
click to toggle source
# File lib/lono/importer/params.rb, line 8 def initialize(template_path, params_path) @template_path, @params_path = template_path, params_path @params_path = normalize_path(@params_path) self.destination_root = Dir.pwd # Thor::Actions require destination_root to be set @options = {} # For Thor::Actions to work end
Public Instance Methods
create()
click to toggle source
Creates starter params/base/.txt file
# File lib/lono/importer/params.rb, line 16 def create result = [] required_parameters.each do |name, attributes| result << "#{name}=#{attributes["Default"]}" end optional_parameters.each do |name, attributes| key = "#{name}=".ljust(20, ' ') result << "##{key} # optional" end content = result.join("\n") + "\n" folder = File.dirname(@params_path) FileUtils.mkdir_p(folder) unless File.exist?(folder) create_file(@params_path, content) # Thor::Action end
optional_parameters()
click to toggle source
# File lib/lono/importer/params.rb, line 37 def optional_parameters parameters.select { |logical_id, p| p["Default"] } end
parameters()
click to toggle source
# File lib/lono/importer/params.rb, line 41 def parameters template_data["Parameters"] || [] end
required_parameters()
click to toggle source
# File lib/lono/importer/params.rb, line 33 def required_parameters parameters.reject { |logical_id, p| p["Default"] } end
template_data()
click to toggle source
# File lib/lono/importer/params.rb, line 45 def template_data YAML.load(IO.read(@template_path)) end
Private Instance Methods
normalize_path(path)
click to toggle source
Add Lono.root if not already there, helps cli_spec.rb to pass
# File lib/lono/importer/params.rb, line 52 def normalize_path(path) path.include?(Lono.root.to_s) ? path : "#{Lono.root}/#{path}" end