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
# File 'lib/rubocop/git/options.rb', line 12

def initialize(hash_options = nil)
  @config  = nil
  @cached  = false
  @hound   = false
  @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

#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



62
63
64
# File 'lib/rubocop/git/options.rb', line 62

def commit_first
  @commits.first
end

#commit_lastObject



66
67
68
# File 'lib/rubocop/git/options.rb', line 66

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

#commits=(commits) ⇒ Object



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

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



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubocop/git/options.rb', line 50

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