Class: RuboCop::Git::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/git/options.rb

Defined Under Namespace

Classes: Invalid

Constant Summary collapse

HOUND_DEFAULT_CONFIG_FILE =
File.expand_path('../../../hound.yml', __dir__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_options = nil) ⇒ Options

Returns a new instance of Options.



10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/git/options.rb', line 10

def initialize(hash_options = nil)
  @config  = nil
  @cached  = false
  @hound   = false
  @format = RuboCop::Formatter::ClangStyleFormatter
  @rubocop = {}
  @commits = []

  from_hash(hash_options) if hash_options
end

Instance Attribute Details

#cachedObject

Returns the value of attribute cached.



8
9
10
# File 'lib/rubocop/git/options.rb', line 8

def cached
  @cached
end

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/rubocop/git/options.rb', line 7

def config
  @config
end

#formatObject

Returns the value of attribute format.



8
9
10
# File 'lib/rubocop/git/options.rb', line 8

def format
  @format
end

#houndObject

Returns the value of attribute hound.



8
9
10
# File 'lib/rubocop/git/options.rb', line 8

def hound
  @hound
end

#rubocopObject

Returns the value of attribute rubocop.



8
9
10
# File 'lib/rubocop/git/options.rb', line 8

def rubocop
  @rubocop
end

Instance Method Details

#commit_firstObject



73
74
75
# File 'lib/rubocop/git/options.rb', line 73

def commit_first
  @commits.first
end

#commit_lastObject



77
78
79
# File 'lib/rubocop/git/options.rb', line 77

def commit_last
  @commits.length == 1 ? false : @commits.last
end

#commits=(commits) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/git/options.rb', line 41

def commits=(commits)
  unless commits.is_a?(Array) && commits.length <= 2
    raise Invalid, "invalid commits: #{commits.inspect}"
  end
  if !commits.empty? && cached
    raise Invalid, 'cached and commit cannot be specified together'
  end

  @commits = commits
end

#config_fileObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubocop/git/options.rb', line 61

def config_file
  if hound
    HOUND_DEFAULT_CONFIG_FILE
  elsif config
    config
  elsif File.exist?(RuboCop::ConfigLoader::DOTFILE)
    RuboCop::ConfigLoader::DOTFILE
  else
    RuboCop::ConfigLoader::DEFAULT_FILE
  end
end