Class: Lono::Pro::Importer::Params
- Inherits:
-
Object
- Object
- Lono::Pro::Importer::Params
- Extended by:
- Memoist
- Includes:
- Thor::Actions, Thor::Base
- Defined in:
- lib/lono/pro/importer/params.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#create ⇒ Object
Creates starter params/base/.txt file.
-
#initialize(template_path, params_path) ⇒ Params
constructor
A new instance of Params.
- #optional_parameters ⇒ Object
- #parameters ⇒ Object
- #required_parameters ⇒ Object
- #template_data ⇒ Object
Constructor Details
#initialize(template_path, params_path) ⇒ Params
Returns a new instance of Params.
8 9 10 11 12 13 |
# File 'lib/lono/pro/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
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/lono/pro/importer/params.rb', line 7 def @options end |
Instance Method Details
#create ⇒ Object
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/pro/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 ⇒ Object
37 38 39 |
# File 'lib/lono/pro/importer/params.rb', line 37 def optional_parameters parameters.select { |logical_id, p| p["Default"] } end |
#parameters ⇒ Object
41 42 43 |
# File 'lib/lono/pro/importer/params.rb', line 41 def parameters template_data["Parameters"] || [] end |
#required_parameters ⇒ Object
33 34 35 |
# File 'lib/lono/pro/importer/params.rb', line 33 def required_parameters parameters.reject { |logical_id, p| p["Default"] } end |
#template_data ⇒ Object
45 46 47 |
# File 'lib/lono/pro/importer/params.rb', line 45 def template_data YAML.load(IO.read(@template_path)) end |