Class: Lono::Importer::Params

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Thor::Actions, Thor::Base
Defined in:
lib/lono/importer/params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path, params_path) ⇒ Params

Returns a new instance of Params.



8
9
10
11
12
13
# 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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/lono/importer/params.rb', line 7

def options
  @options
end

Instance Method Details

#createObject

Creates starter params/base/.txt file



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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_parametersObject



37
38
39
# File 'lib/lono/importer/params.rb', line 37

def optional_parameters
  parameters.select { |logical_id, p| p["Default"] }
end

#parametersObject



41
42
43
# File 'lib/lono/importer/params.rb', line 41

def parameters
  template_data["Parameters"] || []
end

#required_parametersObject



33
34
35
# File 'lib/lono/importer/params.rb', line 33

def required_parameters
  parameters.reject { |logical_id, p| p["Default"] }
end

#template_dataObject



45
46
47
# File 'lib/lono/importer/params.rb', line 45

def template_data
  YAML.load(IO.read(@template_path))
end