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', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_options = nil) ⇒ Options

Returns a new instance of Options.



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

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.



10
11
12
# File 'lib/rubocop/git/options.rb', line 10

def cached
  @cached
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#formatObject

Returns the value of attribute format.



10
11
12
# File 'lib/rubocop/git/options.rb', line 10

def format
  @format
end

#houndObject

Returns the value of attribute hound.



10
11
12
# File 'lib/rubocop/git/options.rb', line 10

def hound
  @hound
end

#rubocopObject

Returns the value of attribute rubocop.



10
11
12
# File 'lib/rubocop/git/options.rb', line 10

def rubocop
  @rubocop
end

Instance Method Details

#commit_firstObject



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

def commit_first
  @commits.first
end

#commit_lastObject



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

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

#commits=(commits) ⇒ Object



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

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

#config_fileObject



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

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