Module: Nutella::CurrentProjectUtils

Defined in:
lib/config/current_project.rb

Class Method Summary collapse

Class Method Details

.configPersistedHash

Builds a PersistedHash of the project nutella.json file and returns it. This method is used to ease access to the project nutella.json file.

Returns:

  • the PersistedHash of the project nutella.json file



30
31
32
33
34
35
36
37
38
# File 'lib/config/current_project.rb', line 30

def CurrentProjectUtils.config
  cur_prj_dir = Dir.pwd
  nutella_json_file = "#{cur_prj_dir}/nutella.json"
  if File.exist? nutella_json_file
    return PersistedHash.new nutella_json_file
    else
      console.error 'The current directory is not a nutella project: impossible to read nutella.json file'
    end
end

.dirString

Retrieves the current project directory

Returns:

  • the current project home



42
43
44
# File 'lib/config/current_project.rb', line 42

def CurrentProjectUtils.dir
  Dir.pwd
end

.exist?Boolean

Checks that the current directory is actually a nutella project

Returns:

  • true if the current directory is a nutella project, false otherwise



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/config/current_project.rb', line 10

def CurrentProjectUtils.exist?
  cur_prj_dir = Dir.pwd
  nutella_json_file = "#{cur_prj_dir}/nutella.json"
  # Check that there is a nutella.json file in the main directory of the project
  if File.exist? nutella_json_file
    conf = JSON.parse( IO.read(nutella_json_file) )
    if conf['nutella_version'].nil?
      console.warn 'The current directory is not a nutella project: nutella_version unspecified in nutella.json file'
      return false
    end
  else
    console.warn 'The current directory is not a nutella project: impossible to read nutella.json file'
    return false
  end
  true
end