Sha256: 4a65183ad3e8360f64ff1457023d96afb0d5cc52b28c11d22243285a87a0b36a

Contents?: true

Size: 1.69 KB

Versions: 59

Compression:

Stored size: 1.69 KB

Contents

require 'json'

module Nutella

  # This module contains a series of utilities methods to handle the nutella
  # application contained in the directory we are at this moment
  module CurrentAppUtils
    
    # Checks that the current directory is actually a nutella application
    # @return [Boolean] true if the current directory is a nutella application, false otherwise
    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

    # 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
    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
    
  end


  # Calling this method (Nutella.current_app) simply returns
  # a reference to the CurrentAppUtils module
  def Nutella.current_app
    CurrentAppUtils
  end
  
end



Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
nutella_framework-0.4.23 lib/config/current_app_utils.rb
nutella_framework-0.4.22 lib/config/current_app_utils.rb
nutella_framework-0.4.21 lib/config/current_app_utils.rb
nutella_framework-0.4.20 lib/config/current_app_utils.rb
nutella_framework-0.4.19 lib/config/current_app_utils.rb
nutella_framework-0.4.18 lib/config/current_app_utils.rb
nutella_framework-0.4.17 lib/config/current_app_utils.rb
nutella_framework-0.4.16 lib/config/current_app_utils.rb
nutella_framework-0.4.13 lib/config/current_app_utils.rb
nutella_framework-0.4.12 lib/config/current_app_utils.rb
nutella_framework-0.4.11 lib/config/current_app_utils.rb
nutella_framework-0.4.10 lib/config/current_app_utils.rb
nutella_framework-0.4.9 lib/config/current_app_utils.rb
nutella_framework-0.4.8 lib/config/current_app_utils.rb
nutella_framework-0.4.5 lib/config/current_app_utils.rb
nutella_framework-0.4.4 lib/config/current_app_utils.rb
nutella_framework-0.4.3 lib/config/current_app_utils.rb
nutella_framework-0.4.2 lib/config/current_app_utils.rb
nutella_framework-0.4.1 lib/config/current_app_utils.rb