class RubyCritic::Cli::Options::File

Attributes

filename[R]
options[R]

Public Class Methods

new(filename = './.rubycritic.yml') click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 11
def initialize(filename = './.rubycritic.yml')
  @filename = filename
  @options = {}
end

Public Instance Methods

parse() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 16
def parse
  @options = YAML.load_file(filename) if ::File.file?(filename)
end
to_h() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/rubycritic/cli/options/file.rb, line 21
def to_h
  {
    mode: mode,
    root: root,
    formats: formats,
    deduplicate_symlinks: deduplicate_symlinks,
    paths: paths,
    suppress_ratings: suppress_ratings,
    minimum_score: minimum_score,
    no_browser: no_browser,
    base_branch: base_branch,
    feature_branch: feature_branch,
    threshold_score: threshold_score
  }
end

Private Instance Methods

base_branch() click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/rubycritic/cli/options/file.rb, line 40
def base_branch
  return options.dig('mode_ci', 'branch') || 'master' if options.dig('mode_ci', 'enabled').to_s == 'true'

  options['branch']
end
feature_branch() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 54
def feature_branch
  SourceControlSystem::Git.current_branch if base_branch
end
formats() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 78
def formats
  formats = Array(options['formats'])
  formats.select do |format|
    %w[html json console lint].include?(format)
  end.map(&:to_sym)
end
minimum_score() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 85
def minimum_score
  options['minimum_score']
end
mode() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 46
def mode
  if options.dig('mode_ci', 'enabled').to_s == 'true'
    :ci
  elsif base_branch
    :compare_branches
  end
end
no_browser() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 74
def no_browser
  value_for(options['no_browser'])
end
paths() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 89
def paths
  options['paths']
end
root() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 58
def root
  options['path']
end
suppress_ratings() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 70
def suppress_ratings
  value_for(options['suppress_ratings'])
end
threshold_score() click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 62
def threshold_score
  options['threshold_score']
end
value_for(value) click to toggle source
# File lib/rubycritic/cli/options/file.rb, line 93
def value_for(value)
  value = value.to_s
  value == 'true' unless value.empty?
end