Class: Nugrant::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/nugrant/config.rb

Constant Summary collapse

DEFAULT_PARAMS_FILENAME =
".vagrantuser"
DEFAULT_PARAMS_FILETYPE =
"yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



27
28
29
30
31
32
33
34
35
36
# File 'lib/nugrant/config.rb', line 27

def initialize(options = {})
  options.delete_if { |key, value| value == nil }

  @params_filename = options.fetch(:params_filename, DEFAULT_PARAMS_FILENAME)
  @params_filetype = options.fetch(:params_filetype, DEFAULT_PARAMS_FILETYPE)

  @project_params_path = options.fetch(:project_params_path, nil)
  @user_params_path = options.fetch(:user_params_path, nil)
  @system_params_path = options.fetch(:system_params_path, nil)
end

Instance Attribute Details

#params_filenameObject

Returns the value of attribute params_filename.



8
9
10
# File 'lib/nugrant/config.rb', line 8

def params_filename
  @params_filename
end

#params_filetypeObject

Returns the value of attribute params_filetype.



9
10
11
# File 'lib/nugrant/config.rb', line 9

def params_filetype
  @params_filetype
end

Class Method Details

.on_windows?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nugrant/config.rb', line 23

def self.on_windows?()
  (RbConfig::CONFIG['host_os'].downcase =~ /mswin|mingw|cygwin/) != nil
end

.system_base_pathObject



15
16
17
18
19
20
21
# File 'lib/nugrant/config.rb', line 15

def self.system_base_path()
  if Config.on_windows?
    return File.expand_path(ENV['PROGRAMDATA'] || ENV['ALLUSERSPROFILE'])
  end

  "/etc"
end

.user_base_pathObject



11
12
13
# File 'lib/nugrant/config.rb', line 11

def self.user_base_path()
  File.expand_path("~")
end

Instance Method Details

#project_params_pathObject



38
39
40
# File 'lib/nugrant/config.rb', line 38

def project_params_path()
  File.expand_path(@project_params_path || "./#{@params_filename}")
end

#system_params_pathObject



46
47
48
# File 'lib/nugrant/config.rb', line 46

def system_params_path()
  File.expand_path(@system_params_path || "#{Config.system_base_path()}/#{@params_filename}")
end

#user_params_pathObject



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

def user_params_path()
  File.expand_path(@user_params_path || "#{Config.user_base_path()}/#{@params_filename}")
end