Module: DiffInfluence::Config

Defined in:
lib/diff_influence/config.rb,
lib/diff_influence/config_1x.rb

Constant Summary collapse

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

:Usage => diff_influence [Options]

 :Options => 
 -c --commit id1,id2,...          git commit id(s) uses diff (:default => none)
 -d --dir  dir1,dir2,...          path(s) to search file (:default => app,lib)
 -e --ext  ext1,ext2,...          extension(s) to search file (:default => rb)
 -i --ignore method1,method2,...  ignore methods (:default => new, index)
 -g --grep                        use grep command with OS
 -P --print                       print config values
 -D --debug                       print debugging information to console

 Feature :Options => 
 -o --output path                 to output file (:default => STDOUT)
==============================================================================
EOS

Class Method Summary collapse

Class Method Details

.commitsObject



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

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

.commits=(value) ⇒ Object



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

def self.commits=(value)
  @@commits = self.flexible_value value
end

.debugObject



77
78
79
# File 'lib/diff_influence/config.rb', line 77

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

.debug=(value) ⇒ Object



81
82
83
# File 'lib/diff_influence/config.rb', line 81

def self.debug=(value)
  @@debug =value
end

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



27
28
29
30
31
# File 'lib/diff_influence/config.rb', line 27

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

.ignore_methodsObject



85
86
87
# File 'lib/diff_influence/config.rb', line 85

def self.ignore_methods
  @@ignore_methods ||= %w(new index)
end

.ignore_methods=(value) ⇒ Object



89
90
91
# File 'lib/diff_influence/config.rb', line 89

def self.ignore_methods=(value)
  @@ignore_methods = self.flexible_value value
end

.load_confObject



93
94
95
96
97
98
99
100
101
# File 'lib/diff_influence/config.rb', line 93

def self.load_conf
  ['.diff-influence', "#{File.expand_path("~")}/\.diff-influence"].each do |conf_file|
    if File.exist? conf_file
      puts "#{conf_file} reading..." if self.debug
      self.load_conf_file conf_file
      break
    end
  end
end

.os_grepObject



69
70
71
# File 'lib/diff_influence/config.rb', line 69

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

.os_grep=(value) ⇒ Object



73
74
75
# File 'lib/diff_influence/config.rb', line 73

def self.os_grep=(value)
  @@os_grep = value
end

.outputObject



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

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

.output=(value) ⇒ Object



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

def self.output=(value)
  @@output = value
end

.parse_args(argv) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/diff_influence/config.rb', line 103

def self.parse_args(argv)
  while arg = argv.shift
    case arg
    when /\A--commit\z/, /\A-c\z/
      self.commits = argv.shift
    when /\A--dir\z/, /\A-d\z/
      self.search_directories = argv.shift
    when /\A--ext\z/, /\A-e\z/
      self.search_extensions = argv.shift
    when /\A--ignore\z/, /\A-i\z/
      self.ignore_methods = argv.shift
    when /\A--output\z/, /\A-o\z/
      self.output = argv.shift
    when /\A--grep\z/, /\A-g\z/
      self.os_grep = true
    when /\A--debug\z/, /\A-D\z/
      self.debug = true
    when /\A--print\z/, /\A-P\z/
      self.print
      self.exit_with_message 0, false
    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


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/diff_influence/config.rb', line 133

def self.print
  yaml_obj = {
    commits: self.commits,
    search_directories: self.search_directories,
    search_extensions: self.search_extensions,
    ignore_methods: self.ignore_methods,
    os_grep: self.os_grep,
    debug: self.debug
  }
  yaml_obj[:output] = self.output if self.output
  puts <<-EOS
======== Diff Influence Config ========
  target commits:     #{self.commits.inspect}
  search directories: #{self.search_directories.inspect}
  search extensions:  #{self.search_extensions.inspect}
  ignore methods:     #{self.ignore_methods.inspect}
  output file:        #{self.output}
  os grep mode:       #{self.os_grep}
  debug mode:         #{self.debug}
=======================================

>>>>> sample .diff_influence
#{YAML.dump yaml_obj}
<<<<<
  EOS
  yaml_obj = nil
end

.rootObject



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

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

.search_directoriesObject



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

def self.search_directories
  @@search_directories ||= %w(app lib)
end

.search_directories=(value) ⇒ Object



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

def self.search_directories=(value)
  @@search_directories = self.flexible_value value
end

.search_extensionsObject



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

def self.search_extensions
  @@search_extensions ||= %w(rb)
end

.search_extensions=(value) ⇒ Object



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

def self.search_extensions=(value)
  @@search_extensions = self.flexible_value value
end