Class: Maximus::Config

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/maximus/config.rb

Overview

Global options and configuration

Since:

  • 0.1.3

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

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

    options passed directly to config

Options Hash (opts):

  • :is_dev (Boolean) — default: false

    whether or not the class was initialized from the command line

  • :log (String, Boolean, nil) — default: 'log/maximus_git.log'

    path to log file If not set, logger outputs to STDOUT

  • :git_log (String, Boolean) — default: false

    path to log file or don’t log The git gem is very noisey

  • :root_dir (String)

    base directory

  • :domain (String) — default: 'http://localhost'

    the host - used for Statistics

  • :port (String, Integer) — default: ''

    port number - used for Statistics and appended to domain. If blank (false, empty string, etc.), will not append to domain

  • :file_paths (String, Array) — default: ''

    path to files. Accepts glob notation

  • :paths (Hash) — default: {home: '/'}

    labeled relative path to URLs. Statistics only

  • :commit (String)

    accepts sha, “working”, “last”, or “master”.

  • :config_file (String) — default: 'maximus.yml'

    path to config file

  • :compile_assets (Boolean) — default: true

    compile and destroy assets automagically

  • :framework (String) — default: nil

    accepts ‘rails’ and ‘middleman’ (should only be used when calling Maximus from a Ruby script)

Since:

  • 0.1.3



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? }

  default_options = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'maximus.yml')).symbolize_keys
  default_options[:root_dir] = root_dir
  default_options[:port] = 3000 if is_rails?
  default_options[:port] = 4567 if is_middleman?

  root = opts[:root_dir] ? opts[:root_dir] : default_options[:root_dir]

  yaml = default_options.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

#settingsHash (readonly)

all the options

Returns:

  • (Hash)

    the current value of settings

Since:

  • 0.1.3



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

def settings
  @settings
end

#temp_filesHash (readonly)

Filename without extension => path to temp file

Returns:

  • (Hash)

    the current value of temp_files

Since:

  • 0.1.3



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

Parameters:

  • filename (String) (defaults to: nil)

    (nil) file to destroy If nil, destroy all temp files

See Also:

  • #temp_it

Since:

  • 0.1.3



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

#domainString

Combine domain with port if necessary

Returns:

  • (String)

    complete domain/host address

Since:

  • 0.1.3



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

Parameters:

  • settings_data (Hash) (defaults to: @settings)

    (@settings) loaded data from the discovered maximus config file

Returns:

  • (Hash)

    paths to temp config files and static options These should be deleted with destroy_temp after read and loaded

Since:

  • 0.1.3



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

Returns:

  • (Boolean)

Since:

  • 0.1.3



124
125
126
# File 'lib/maximus/config.rb', line 124

def is_dev?
  @settings[:is_dev]
end

#working_dirString

Grab root directory

Returns:

  • (String)

Since:

  • 0.1.6



131
132
133
# File 'lib/maximus/config.rb', line 131

def working_dir
  @settings[:root_dir]
end