module Nutella::CurrentAppUtils

This module contains a series of utilities methods to handle the nutella application contained in the directory we are at this moment

Public Class Methods

config() click to toggle source

Builds a PersistedHash of the application nutella.json file and returns it. This method is used to ease access to the app nutella.json file. @return [PersistedHash] the PersistedHash of the app nutella.json file

# File lib/config/current_app_utils.rb, line 35
def CurrentAppUtils.config
  cur_app_dir = Dir.pwd
  nutella_json_file = "#{cur_app_dir}/nutella.json"
  if File.exist? nutella_json_file
    return PersistedHash.new(nutella_json_file)
  else
    raise 'The current directory is not a nutella app: impossible to read nutella.json file'
  end
end
exist?() click to toggle source

Checks that the current directory is actually a nutella application @return [Boolean] true if the current directory is a nutella application, false otherwise

# File lib/config/current_app_utils.rb, line 11
def CurrentAppUtils.exist?
  cur_app_dir = Dir.pwd
  nutella_json_file = "#{cur_app_dir}/nutella.json"
  # Check that there is a nutella.json file in the main directory of the application
  if File.exist? nutella_json_file
    begin
      conf = JSON.parse( IO.read(nutella_json_file) )
    rescue
      console.warn 'The nutella.json file for this application does not contain properly formatted JSON'
      return false
    end

    if conf['nutella_version'].nil?
      return false
    end
  else
    return false
  end
  true
end