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.
-
#working_dir ⇒ String
Grab root directory.
Methods included from Helper
#discover_path, #edit_yaml, #file_count, #file_list, #is_middleman?, #is_rails?, #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
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 |
# File 'lib/maximus/config.rb', line 38 def initialize(opts = {}) # Strips from command line opts = opts.delete_if { |k, v| v.nil? } = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'maximus.yml')).symbolize_keys [:root_dir] = root_dir [:port] = 3000 if is_rails? [:port] = 4567 if is_middleman? root = opts[:root_dir] ? opts[:root_dir] : [:root_dir] yaml = .merge load_config_file(opts[:config_file], root) @settings = yaml.merge opts @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
11 12 13 |
# File 'lib/maximus/config.rb', line 11 def settings @settings end |
#temp_files ⇒ Hash (readonly)
Filename without extension => path to temp file
11 12 13 |
# File 'lib/maximus/config.rb', line 11 def temp_files @temp_files end |
Instance Method Details
#destroy_temp(filename = nil) ⇒ Object
Remove all or one created temporary config file
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/maximus/config.rb', line 139 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
152 153 154 |
# File 'lib/maximus/config.rb', line 152 def domain @settings[:port].blank? ? @settings[:domain] : "#{@settings[:domain]}:#{@settings[:port]}" end |
#evaluate_settings(settings_data = @settings) ⇒ Hash
Set global options or generate appropriate config files for lints or statistics
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 |
# File 'lib/maximus/config.rb', line 72 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 value = load_config(value) jshint_ignore settings_data[key] @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 @settings end |
#is_dev? ⇒ Boolean
If output should be returned to console in a pretty display
124 125 126 |
# File 'lib/maximus/config.rb', line 124 def is_dev? @settings[:is_dev] end |
#working_dir ⇒ String
Grab root directory
131 132 133 |
# File 'lib/maximus/config.rb', line 131 def working_dir @settings[:root_dir] end |