Class: SQA::Config

Inherits:
Hashie::Dash
  • Object
show all
Includes:
Hashie::Extensions::Coercion, Hashie::Extensions::Dash::PropertyTranslation, Hashie::Extensions::MethodAccess
Defined in:
lib/sqa/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_hash = {}) ⇒ Config

Returns a new instance of Config.



75
76
77
78
# File 'lib/sqa/config.rb', line 75

def initialize(a_hash={})
  super(a_hash)
  override_with_envars
end

Class Method Details

.resetObject



188
189
190
# File 'lib/sqa/config.rb', line 188

def reset
  SQA.config = new
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


80
# File 'lib/sqa/config.rb', line 80

def debug?    = debug

#dump_fileObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sqa/config.rb', line 118

def dump_file
  if config_file.nil?
    raise BadParameterError, "No config file given"
  end

  `touch #{config_file}`
  # unless  File.exist?(config_file)

  type = File.extname(config_file).downcase

  if ".json" == type
    dump_json

  elsif %w[.yml .yaml].include?(type)
    dump_yaml

  elsif ".toml" == type
    dump_toml

  else
    raise BadParameterError, "Invalid Config File Type: #{config_file}"
  end
end

#from_fileObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sqa/config.rb', line 85

def from_file
  return if config_file.nil?

  if  File.exist?(config_file)    &&
      File.file?(config_file)     &&
      File.readable?(config_file)
    type = File.extname(config_file).downcase
  else
    type = "invalid"
  end

  # TODO: arrange order in mostly often used

  if ".json" == type
    incoming = form_json

  elsif %w[.yml .yaml].include?(type)
    incoming = from_yaml

  elsif ".toml" == type
    incoming = from_toml

  else
    raise BadParameterError, "Invalid Config File: #{config_file}"
  end

  if incoming.has_key? :data_dir
    incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
  end

  merge! incoming
end

#inject_additional_propertiesObject

Method to dynamically extend properties from external sources (e.g., plugins)



143
144
145
146
147
# File 'lib/sqa/config.rb', line 143

def inject_additional_properties
  SQA::PluginManager.registered_properties.each do |prop, options|
    self.class.property(prop, options)
  end
end

#verbose?Boolean

Returns:

  • (Boolean)


81
# File 'lib/sqa/config.rb', line 81

def verbose?  = verbose