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

Overview

Configuration class for SQA settings. Extends Hashie::Dash for property-based configuration with coercion.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_hash = {}) ⇒ Config

Creates a new Config instance with optional initial values. Automatically applies environment variable overrides.

Parameters:

  • a_hash (Hash) (defaults to: {})

    Initial configuration values



120
121
122
123
# File 'lib/sqa/config.rb', line 120

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

Instance Attribute Details

#commandString?

Returns Current command (nil, ‘analysis’, or ‘web’).

Returns:

  • (String, nil)

    Current command (nil, ‘analysis’, or ‘web’)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#config_fileString?

Returns Path to configuration file.

Returns:

  • (String, nil)

    Path to configuration file



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#data_dirString

Returns Directory for data storage (default: ~/sqa_data).

Returns:

  • (String)

    Directory for data storage (default: ~/sqa_data)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#debugBoolean

Returns Enable debug mode.

Returns:

  • (Boolean)

    Enable debug mode



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#dump_configString?

Returns Path to dump current configuration.

Returns:

  • (String, nil)

    Path to dump current configuration



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#lazy_updateBoolean

Returns Skip API updates if cached data exists.

Returns:

  • (Boolean)

    Skip API updates if cached data exists



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#log_levelSymbol

Returns Log level (:debug, :info, :warn, :error, :fatal).

Returns:

  • (Symbol)

    Log level (:debug, :info, :warn, :error, :fatal)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#plotting_librarySymbol

Returns Plotting library to use (:gruff).

Returns:

  • (Symbol)

    Plotting library to use (:gruff)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#portfolio_filenameString

Returns Portfolio CSV filename (default: portfolio.csv).

Returns:

  • (String)

    Portfolio CSV filename (default: portfolio.csv)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#trades_filenameString

Returns Trades CSV filename (default: trades.csv).

Returns:

  • (String)

    Trades CSV filename (default: trades.csv)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

#verboseBoolean

Returns Enable verbose output.

Returns:

  • (Boolean)

    Enable verbose output



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/sqa/config.rb', line 54

class Config < Hashie::Dash
  include Hashie::Extensions::Dash::PropertyTranslation
  include Hashie::Extensions::MethodAccess
  include Hashie::Extensions::Coercion

  # NOTE: PredefinedValues extension disabled due to compatibility issues.
  # Log level validation is handled via the `values:` option on the property instead.
  # include Hashie::Extensions::Dash::PredefinedValues

  property :command       # a String currently, nil, analysis or web
  property :config_file   # a String filepath for the current config overriden by cli options
  property :dump_config   # a String filepath into which to dump the current config

  property :data_dir,     default: Nenv.home + "/sqa_data"

  # Relative filenames are resolved against data_dir; absolute paths used as-is
  property :portfolio_filename, from: :portfolio, default: "portfolio.csv"
  property :trades_filename,    from: :trades,    default: "trades.csv"

  property :log_level,    default: :info,  coerce: Symbol, values: i[debug info warn error fatal]

  # Boolean coercion handled via coerce_key blocks below (no Boolean class in Ruby)
  property :debug,        default: false
  property :verbose,      default: false

  # Plotting library - gruff is default; svggraph support could be added in future
  property :plotting_library, from: :plot_lib,  default: :gruff, coerce: Symbol
  property :lazy_update,      from: :lazy,      default: false


  coerce_key :debug, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :verbose, ->(v) do
    case v
    when String
      !!(v =~ /\A(true|t|yes|y|1)\z/i)
    when Numeric
      !v.to_i.zero?
    else
      v == true
    end
  end

  coerce_key :log_level, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  coerce_key :plotting_library, ->(v) do
    v.is_a?(String) ? v.to_sym : v
  end

  ########################################################

  # Creates a new Config instance with optional initial values.
  # Automatically applies environment variable overrides.
  #
  # @param a_hash [Hash] Initial configuration values
  def initialize(a_hash={})
    super(a_hash)
    override_with_envars
  end

  # Returns whether debug mode is enabled.
  # @return [Boolean] true if debug mode is on
  def debug?    = debug

  # Returns whether verbose mode is enabled.
  # @return [Boolean] true if verbose mode is on
  def verbose?  = verbose


  ########################################################

  # Loads configuration from a file.
  # Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is invalid or unsupported format
  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

    # Config file format detection (YAML is most common)
    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.key?(:data_dir)
      incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
    end

    merge! incoming
  end

  # Writes current configuration to a file.
  # Format is determined by file extension.
  #
  # @return [void]
  # @raise [BadParameterError] If config file is not set or unsupported format
  def dump_file
    if config_file.nil?
      raise BadParameterError, "No config file given"
    end

    FileUtils.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

  # Injects additional properties from plugins.
  # Allows external code to register new configuration options.
  #
  # @return [void]
  def inject_additional_properties
    SQA::PluginManager.registered_properties.each do |prop, options|
      self.class.property(prop, options)
    end
  end


  ########################################################
  private

  def override_with_envars(prefix = "SQA_")
    keys.each do |key|
      envar = ENV["#{prefix}#{key.to_s.upcase}"]
      send("#{key}=", envar) unless envar.nil?
    end
  end


  #####################################
  ## override values from a config file

  def from_json
    ::JSON.load(File.open(config_file).read).symbolize_keys
  end

  def from_toml
    TomlRB.load_file(config_file).symbolize_keys
  end

  def from_yaml
    ::YAML.load_file(config_file).symbolize_keys
  end


  #####################################
  ## dump values to a config file

  def as_hash   = to_h.reject{|k, _| :config_file == k}
  def dump_json = File.open(config_file, "w") { |f| f.write JSON.pretty_generate(as_hash)}
  def dump_toml = File.open(config_file, "w") { |f| f.write TomlRB.dump(as_hash)}
  def dump_yaml = File.open(config_file, "w") { |f| f.write as_hash.to_yaml}


  #####################################
  class << self
    # Resets the configuration to default values.
    # Creates a new Config instance and assigns it to SQA.config.
    #
    # @return [SQA::Config] The new config instance
    def reset
      @initialized = true
      SQA.config = new
    end

    # Returns whether the configuration has been initialized.
    #
    # @return [Boolean] true if reset has been called
    def initialized?
      @initialized ||= false
    end
  end
end

Class Method Details

.initialized?Boolean

Returns whether the configuration has been initialized.

Returns:

  • (Boolean)

    true if reset has been called



263
264
265
# File 'lib/sqa/config.rb', line 263

def initialized?
  @initialized ||= false
end

.resetSQA::Config

Resets the configuration to default values. Creates a new Config instance and assigns it to SQA.config.

Returns:



255
256
257
258
# File 'lib/sqa/config.rb', line 255

def reset
  @initialized = true
  SQA.config = new
end

Instance Method Details

#debug?Boolean

Returns whether debug mode is enabled.

Returns:

  • (Boolean)

    true if debug mode is on



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

def debug?    = debug

#dump_filevoid

This method returns an undefined value.

Writes current configuration to a file. Format is determined by file extension.

Raises:



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/sqa/config.rb', line 178

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

  FileUtils.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_filevoid

This method returns an undefined value.

Loads configuration from a file. Supports YAML (.yml, .yaml), TOML (.toml), and JSON (.json) formats.

Raises:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/sqa/config.rb', line 141

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

  # Config file format detection (YAML is most common)
  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.key?(:data_dir)
    incoming[:data_dir] = incoming[:data_dir].gsub(/^~/, Nenv.home)
  end

  merge! incoming
end

#inject_additional_propertiesvoid

This method returns an undefined value.

Injects additional properties from plugins. Allows external code to register new configuration options.



206
207
208
209
210
# File 'lib/sqa/config.rb', line 206

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

#verbose?Boolean

Returns whether verbose mode is enabled.

Returns:

  • (Boolean)

    true if verbose mode is on



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

def verbose?  = verbose