Class: Configure::Questioner
- Inherits:
-
Object
- Object
- Configure::Questioner
- Defined in:
- lib/ngi/configure.rb
Overview
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.)
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#components_hash ⇒ Object
readonly
Returns the value of attribute components_hash.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#configurable ⇒ Object
readonly
Returns the value of attribute configurable.
-
#file ⇒ Object
Returns the value of attribute file.
-
#lang_types ⇒ Object
readonly
Returns the value of attribute lang_types.
-
#languages ⇒ Object
readonly
Returns the value of attribute languages.
Class Method Summary collapse
Instance Method Summary collapse
- #choose_configurable_property ⇒ Object
-
#configure_property(property) ⇒ Object
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.
-
#initialize(args) {|_self| ... } ⇒ Questioner
constructor
A new instance of Questioner.
Constructor Details
#initialize(args) {|_self| ... } ⇒ Questioner
Returns a new instance of Questioner.
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# 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 |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def components @components end |
#components_hash ⇒ Object (readonly)
Returns the value of attribute components_hash.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def components_hash @components_hash end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def config @config end |
#configurable ⇒ Object (readonly)
Returns the value of attribute configurable.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def configurable @configurable end |
#file ⇒ Object
Returns the value of attribute file.
219 220 221 |
# File 'lib/ngi/configure.rb', line 219 def file @file end |
#lang_types ⇒ Object (readonly)
Returns the value of attribute lang_types.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def lang_types @lang_types end |
#languages ⇒ Object (readonly)
Returns the value of attribute languages.
220 221 222 |
# File 'lib/ngi/configure.rb', line 220 def languages @languages end |
Class Method Details
.run(file) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# 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 |
Instance Method Details
#choose_configurable_property ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 |
# 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) ⇒ Object
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
259 260 261 262 263 264 265 266 |
# 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 |