Class: Maximus::Config
Overview
Global options and configuration
Instance Attribute Summary collapse
-
#settings ⇒ Hash
readonly
all the options.
-
#temp_files ⇒ Hash
readonly
Filename without extension => path to temp file.
Instance Method Summary collapse
-
#destroy_temp(filename = nil) ⇒ Object
Remove all or one created temporary config file.
-
#domain ⇒ String
Combine domain with port if necessary.
-
#evaluate_settings(settings_data = @settings) ⇒ Hash
Set global options or generate appropriate config files for lints or statistics.
-
#initialize(opts = {}) ⇒ #load_config_file #group_families #evaluate_settings
constructor
Global options for all of maximus.
-
#is_dev? ⇒ Boolean
If output should be returned to console in a pretty display.
-
#log ⇒ Logger
Defines base logger.
Methods included from Helper
#check_default_config_path, #edit_yaml, #file_count, #file_list, #is_rails?, #lines_added_to_range, #node_module_exists, #path_exists?, #prompt, #reporter_path, #root_dir, #truthy?
Constructor Details
#initialize(opts = {}) ⇒ #load_config_file #group_families #evaluate_settings
Global options for all of maximus
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/maximus/config.rb', line 35 def initialize(opts = {}) = { root_dir: root_dir, domain: 'http://localhost', port: is_rails? ? 3000 : '', paths: { 'home' => '/' }, is_dev: false, phantomas: false, stylestats: false, wraith: false } yaml = .merge load_config_file(opts[:config_file]) @settings = yaml.merge opts # Only set log file if it's set to true. # Otherwise, allow it to be nil or a path @settings[:log] = false if @settings[:log].nil? @settings[:log] ||= 'log/maximus.log' if @settings[:log].is_a?(TrueClass) @settings[:git_log] = false if @settings[:git_log].nil? @settings[:git_log] ||= 'log/maximus_git.log' if @settings[:git_log].is_a?(TrueClass) @settings[:compile_assets] = true if @settings[:compile_assets].nil? @settings[:paths] = split_paths(@settings[:paths]) if @settings[:paths].is_a?(Array) group_families # Instance variables for Config class only @temp_files = {} # Override options with any defined in a discovered config file evaluate_settings end |
Instance Attribute Details
#settings ⇒ Hash (readonly)
all the options
10 11 12 |
# File 'lib/maximus/config.rb', line 10 def settings @settings end |
#temp_files ⇒ Hash (readonly)
Filename without extension => path to temp file
10 11 12 |
# File 'lib/maximus/config.rb', line 10 def temp_files @temp_files end |
Instance Method Details
#destroy_temp(filename = nil) ⇒ Object
Remove all or one created temporary config file
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/maximus/config.rb', line 155 def destroy_temp(filename = nil) if filename.nil? @temp_files.each { |filename, file| file.unlink } @temp_files = {} else return if @temp_files[filename.to_sym].blank? @temp_files[filename.to_sym].unlink @temp_files.delete(filename.to_sym) end end |
#domain ⇒ String
Combine domain with port if necessary
168 169 170 |
# File 'lib/maximus/config.rb', line 168 def domain (!@settings[:port].blank?) ? "#{@settings[:domain]}:#{@settings[:port]}" : @settings[:domain] end |
#evaluate_settings(settings_data = @settings) ⇒ Hash
Set global options or generate appropriate config files for lints or statistics
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 |
# File 'lib/maximus/config.rb', line 75 def evaluate_settings(settings_data = @settings) settings_data.each do |key, value| next if value.is_a?(FalseClass) value = {} if value.is_a?(TrueClass) case key when :jshint, :JSHint, :JShint # @todo DRY this load_config up, but can't call it at the start because of the # global config variables (last when statement in this switch) value = load_config(value) if settings_data[key].is_a?(Hash) && settings_data[key].has_key?('jshintignore') jshintignore_file = [] settings_data[key]['jshintignore'].each { |i| jshintignore_file << "#{i}\n" } @settings[:jshintignore] = temp_it('jshintignore.json', jshintignore_file) end @settings[:jshint] = temp_it('jshint.json', value.to_json) when :scsslint, :SCSSlint value = load_config(value) @settings[:scsslint] = temp_it('scsslint.yml', value.to_yaml) when :rubocop, :Rubocop, :RuboCop value = load_config(value) @settings[:rubocop] = temp_it('rubocop.yml', value.to_yaml) when :brakeman @settings[:brakeman] = settings_data[key] when :rails_best_practice, :railsbp @settings[:railsbp] = settings_data[key] when :stylestats, :Stylestats value = load_config(value) @settings[:stylestats] = temp_it('stylestats.json', value.to_json) when :phantomas, :Phantomas value = load_config(value) @settings[:phantomas] = temp_it('phantomas.json', value.to_json) when :wraith, :Wraith value = load_config(value) evaluate_for_wraith(value) # Configuration important to all of maximus when :is_dev, :log, :root_dir, :domain, :port, :paths, :commit @settings[key] = settings_data[key] end end # Finally, we're done @settings end |
#is_dev? ⇒ Boolean
If output should be returned to console
in a pretty display
136 137 138 |
# File 'lib/maximus/config.rb', line 136 def is_dev? @settings[:is_dev] end |
#log ⇒ Logger
Defines base logger
144 145 146 147 148 149 |
# File 'lib/maximus/config.rb', line 144 def log out = @settings[:log] || STDOUT @log ||= Logger.new(out) @log.level ||= Logger::INFO @log end |