Method: Configure::Questioner.run

Defined in:
lib/ngi/configure.rb

.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