class Configure::Questioner
Make Questioner
accesible as in: Configure::Questioner.run()
“Questioner” simply starts an interactive prompt to guide the user in configuring src/config/agular_init.config.json, which is a JSON file that holds all the global configurable options (like language to use, templates, etc.)
Attributes
components[R]
components_hash[R]
config[R]
configurable[R]
file[RW]
lang_types[R]
languages[R]
Public Class Methods
new(args) { |self| ... }
click to toggle source
# File lib/ngi/configure.rb, line 227 def initialize(args) @languages = args[:languages] language_types = @languages.select do |type, languages| type if languages.size > 1 end @lang_types = language_types.collect { |type, _| type }.flatten @components_hash = args[:components_hash] @components = args[:components] @config = args[:config] @configurable = args[:configurable] yield(self) if block_given? end
run(file)
click to toggle source
# File lib/ngi/configure.rb, line 268 def self.run(file) questioner = Questioner.new(file) do |q| # First, the user chooses a property # to configure (from a list of available # properties that *can* be configured) property = q.choose_configurable_property # #configure_property spits out a hash # as the result result = q.configure_property(property) # The hash that was spit out as the # result is "merged" into the original # Hash from_json object that came from # config/angular_init.config.json # and is inside of this instance of Questioner q.config[property] = result # delete any properties that are nil q.config.delete_if { |_, v| v.nil? } # This just tells the user that we were # successful result_string_hash = JSer.new(result).to_str rescue 'null' puts "#{property.capitalize} set to: #{result_string_hash}" end # Returns the file so that it can be used # (For example, Configure might write this # new hash as a JSON file to # config/angular_init.config.json) questioner.config end
Public Instance Methods
choose_configurable_property()
click to toggle source
# File lib/ngi/configure.rb, line 241 def choose_configurable_property puts "Current settings\n================" @configurable.each_with_index do |p, i| json_string = 'Currently using default settings' json_string = JSer.new(@config[p]).to_str if @config.key? p puts "#{i + 1}) #{p.capitalize}: #{json_string}" end valid = JSer.new(@configurable).to_str # return AskLoop.ask(check: @configurable, valid: valid) end
configure_property(property)
click to toggle source
This method delegates to the appropriate Configurable#<method> based on the property that the user has chosen to configure Returns: a Hash of the object, based on the from_json config object from config/angular_init.config.json
# File lib/ngi/configure.rb, line 259 def configure_property(property) case property when 'language' return Configurable.language(self) when 'templates' return Configurable.templates(self) end end