Class: Spellr::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/spellr.rb,
lib/spellr/config.rb

Defined Under Namespace

Classes: Invalid, NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



20
21
22
# File 'lib/spellr/config.rb', line 20

def initialize
  @config = ConfigLoader.new
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



17
18
19
# File 'lib/spellr/config.rb', line 17

def config_file
  @config_file
end

#dry_runObject Also known as: dry_run?

Returns the value of attribute dry_run.



15
16
17
# File 'lib/spellr/config.rb', line 15

def dry_run
  @dry_run
end

#parallelObject



71
72
73
# File 'lib/spellr/config.rb', line 71

def parallel
  defined?(@parallel) ? @parallel : default_parallel
end

#reporterObject



67
68
69
# File 'lib/spellr/config.rb', line 67

def reporter
  @reporter ||= default_reporter
end

#suppress_file_rulesObject

Returns the value of attribute suppress_file_rules.



15
16
17
# File 'lib/spellr/config.rb', line 15

def suppress_file_rules
  @suppress_file_rules
end

Instance Method Details

#checkerObject



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

def checker
  return dry_run_checker if dry_run?

  @checker ||= default_checker
end

#excludesObject



40
41
42
# File 'lib/spellr/config.rb', line 40

def excludes
  @excludes ||= @config[:excludes] || []
end

#includesObject



36
37
38
# File 'lib/spellr/config.rb', line 36

def includes
  @includes ||= @config[:includes] || []
end

#key_heuristic_weightObject



28
29
30
# File 'lib/spellr/config.rb', line 28

def key_heuristic_weight
  @key_heuristic_weight ||= @config[:key_heuristic_weight]
end

#key_minimum_lengthObject



32
33
34
# File 'lib/spellr/config.rb', line 32

def key_minimum_length
  @key_minimum_length ||= @config[:key_minimum_length]
end

#languagesObject



44
45
46
47
48
# File 'lib/spellr/config.rb', line 44

def languages
  @languages ||= @config[:languages].map do |key, args|
    Spellr::Language.new(key, **args)
  end
end

#languages_for(file) ⇒ Object



50
51
52
# File 'lib/spellr/config.rb', line 50

def languages_for(file)
  languages.select { |l| l.matches?(file) }
end

#outputObject



63
64
65
# File 'lib/spellr/config.rb', line 63

def output
  @output ||= Spellr::Output.new
end

#reset!Object

rubocop:disable Metrics/MethodLength



85
86
87
88
89
90
91
92
93
# File 'lib/spellr/config.rb', line 85

def reset! # rubocop:disable Metrics/MethodLength
  @config = ConfigLoader.new
  remove_instance_variable(:@languages) if defined?(@languages)
  remove_instance_variable(:@excludes) if defined?(@excludes)
  remove_instance_variable(:@includes) if defined?(@includes)
  remove_instance_variable(:@word_minimum_length) if defined?(@word_minimum_length)
  remove_instance_variable(:@key_heuristic_weight) if defined?(@key_heuristic_weight)
  remove_instance_variable(:@key_minimum_length) if defined?(@key_minimum_length)
end

#valid?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/spellr/config.rb', line 81

def valid?
  Spellr::ConfigValidator.new.valid?
end

#word_minimum_lengthObject



24
25
26
# File 'lib/spellr/config.rb', line 24

def word_minimum_length
  @word_minimum_length ||= @config[:word_minimum_length]
end

#wordlists_for(file) ⇒ Object



54
55
56
# File 'lib/spellr/config.rb', line 54

def wordlists_for(file)
  languages_for(file).flat_map(&:wordlists)
end