Module: DiffInfluence::Config

Defined in:
lib/diff_influence/config.rb

Constant Summary collapse

USAGE =
<<-EOS
==============================================================================
[]: optional

Usage: diff_influence [Options]

 Options:

 -p --path path,path,...           path(s) to search file (default: app,lib)
 -e --ext  extension,extension,... extension(s) to search file (default: rb)
 -g --grep                         use grep command with OS
 -d --debug                        print debugging information to console

 Feature Options:

 -c --commit commit_id,commit_id   git commit id(s) uses diff (default: none)
 -o --output path                  to output file (default: STDOUT)
==============================================================================
EOS

Class Method Summary collapse

Class Method Details

.commitsObject



34
35
36
# File 'lib/diff_influence/config.rb', line 34

def self.commits
  @@commits ||= []
end

.commits=(value) ⇒ Object



38
39
40
# File 'lib/diff_influence/config.rb', line 38

def self.commits=(value)
  @@commits = value.split(",").map{|v| v.chomp.strip}
end

.debugObject



66
67
68
# File 'lib/diff_influence/config.rb', line 66

def self.debug
  @@debug ||= false
end

.exit_with_message(code, usage = false, msg = nil) ⇒ Object



24
25
26
27
28
# File 'lib/diff_influence/config.rb', line 24

def self.exit_with_message(code, usage=false, msg=nil)
  puts msg unless msg.nil?
  puts USAGE if usage
  exit code
end

.os_grepObject



62
63
64
# File 'lib/diff_influence/config.rb', line 62

def self.os_grep
  @@os_grep ||= false
end

.outputObject



58
59
60
# File 'lib/diff_influence/config.rb', line 58

def self.output
  @@output ||= nil
end

.parse_options(argv) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/diff_influence/config.rb', line 70

def self.parse_options(argv)
  while arg = argv.shift
    case arg
    when /\A--commit\z/, /\A-c\z/
      self.commits = argv.shift
    when /\A--path\z/, /\A-p\z/
      self.search_paths = argv.shift
    when /\A--ext\z/, /\A-e\z/
      self.search_extensions = argv.shift
    when /\A--output\z/, /\A-o\z/
      @@output = argv.shift
    when /\A--grep\z/, /\A-g\z/
      @@debug = true
    when /\A--debug\z/, /\A-d\z/
      @@debug = true
    when /\A--help\z/, /\A-h\z/
      self.exit_with_message 0, true
    else
      puts "unknown option #{arg}"
      self.exit_with_message 2, true
    end
  end
  true
end

.rootObject



30
31
32
# File 'lib/diff_influence/config.rb', line 30

def self.root
  @@root ||= Pathname.pwd
end

.search_extensionsObject



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

def self.search_extensions
  @@search_extensions ||= ["rb"]
end

.search_extensions=(value) ⇒ Object



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

def self.search_extensions=(value)
  @@search_extensionss = value.split(",").map{|v| v.chomp.strip}
end

.search_pathsObject



42
43
44
# File 'lib/diff_influence/config.rb', line 42

def self.search_paths
  @@search_paths ||= ["app", "lib"]
end

.search_paths=(value) ⇒ Object



46
47
48
# File 'lib/diff_influence/config.rb', line 46

def self.search_paths=(value)
  @@search_paths = value.split(",").map{|v| v.chomp.strip}
end