watson-ruby 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Watson
2
-
2
+
3
3
  # Color definitions for pretty printing
4
4
  # Defined here because we need Global scope but makes sense to have them
5
5
  # in the printer.rb file at least
@@ -29,38 +29,38 @@ module Watson
29
29
  include Watson
30
30
 
31
31
  # Debug printing for this class
32
- DEBUG = false
32
+ DEBUG = false
33
33
 
34
34
  class << self
35
-
35
+
36
36
  # Include for debug_print (for static methods)
37
37
  include Watson
38
38
 
39
39
  ###########################################################
40
- # Custom color print for static call (only writes to STDOUT)
40
+ # Custom color print for static call (only writes to STDOUT)
41
41
  def cprint (msg = "", color = "")
42
42
 
43
43
  # Identify method entry
44
44
  debug_print "#{ self } : #{ __method__ }\n"
45
-
45
+
46
46
  # This little check will allow us to take a Constant defined color
47
47
  # As well as a [0-256] value if specified
48
- if (color.is_a?(String))
48
+ if (color.is_a?(String))
49
49
  debug_print "Custom color specified for cprint\n"
50
50
  STDOUT.write(color)
51
51
  elsif (color.between?(0, 256))
52
52
  debug_print "No or Default color specified for cprint\n"
53
53
  STDOUT.write("\e[38;5;#{ color }m")
54
54
  end
55
-
55
+
56
56
  STDOUT.write(msg)
57
57
  end
58
58
 
59
59
 
60
60
  ###########################################################
61
- # Standard header print for static call (uses static cprint)
62
- def print_header
63
-
61
+ # Standard header print for static call (uses static cprint)
62
+ def print_header
63
+
64
64
  # Identify method entry
65
65
  debug_print "#{ self } : #{ __method__ }\n"
66
66
 
@@ -76,9 +76,9 @@ module Watson
76
76
 
77
77
 
78
78
  ###########################################################
79
- # Status printer for static call (uses static cprint)
79
+ # Status printer for static call (uses static cprint)
80
80
  # Print status block in standard format
81
- def print_status(msg, color)
81
+ def print_status(msg, color)
82
82
  cprint RESET + BOLD
83
83
  cprint WHITE + "[ "
84
84
  cprint "#{ msg } ", color
@@ -93,19 +93,19 @@ module Watson
93
93
 
94
94
  # Identify method entry
95
95
  debug_print "#{ self } : #{ __method__ }\n"
96
-
96
+
97
97
  @config = config
98
98
  return true
99
- end
99
+ end
100
+
100
101
 
101
-
102
102
  ###########################################################
103
- # Take parsed structure and print out in specified formatting
103
+ # Take parsed structure and print out in specified formatting
104
104
  def run(structure)
105
105
 
106
106
  # Identify method entry
107
107
  debug_print "#{ self } : #{ __method__ }\n"
108
-
108
+
109
109
  # Check Config to see if we have access to less for printing
110
110
  # If so, open our temp file as the output to write to
111
111
  # Else, just print out to STDOUT
@@ -115,8 +115,8 @@ module Watson
115
115
  else
116
116
  debug_print "Unix less is unavaliable, setting output to STDOUT\n"
117
117
  @output = STDOUT
118
- end
119
-
118
+ end
119
+
120
120
  # Print header for output
121
121
  debug_print "Printing Header\n"
122
122
  print_header
@@ -148,7 +148,7 @@ module Watson
148
148
 
149
149
  # This little check will allow us to take a Constant defined color
150
150
  # As well as a [0-256] value if specified
151
- if (color.is_a?(String))
151
+ if (color.is_a?(String))
152
152
  debug_print "Custom color specified for cprint\n"
153
153
  @output.write(color)
154
154
  elsif (color.between?(0, 256))
@@ -159,10 +159,10 @@ module Watson
159
159
  @output.write(msg)
160
160
  end
161
161
 
162
-
162
+
163
163
  ###########################################################
164
164
  # Standard header print for class call (uses member cprint)
165
- def print_header
165
+ def print_header
166
166
  # Identify method entry
167
167
 
168
168
  debug_print "#{ self } : #{ __method__ }\n"
@@ -183,7 +183,7 @@ module Watson
183
183
  ###########################################################
184
184
  # Status printer for member call (uses member cprint)
185
185
  # Print status block in standard format
186
- def print_status(msg, color)
186
+ def print_status(msg, color)
187
187
  cprint RESET + BOLD
188
188
  cprint WHITE + "[ "
189
189
  cprint "#{ msg } ", color
@@ -193,7 +193,7 @@ module Watson
193
193
 
194
194
  ###########################################################
195
195
  # Go through all files and directories and call necessary printing methods
196
- # Print all individual entries, call print_structure on each subdir
196
+ # Print all individual entries, call print_structure on each subdir
197
197
  def print_structure(structure)
198
198
 
199
199
  # Identify method entry
@@ -234,9 +234,9 @@ module Watson
234
234
  cprint "\n"
235
235
  print_status "x", RED
236
236
  cprint BOLD + UNDERLINE + RED + "#{entry[:relative_path]}" + RESET + "\n"
237
- end
237
+ end
238
+
238
239
 
239
-
240
240
  # [review] - Should the tag structure be self contained in the hash
241
241
  # Or is it ok to reference @config to figure out the tags
242
242
  @config.tag_list.each do | _tag |
@@ -249,7 +249,7 @@ module Watson
249
249
  cprint "\n"
250
250
  next
251
251
  end
252
-
252
+
253
253
  debug_print "#{ _tag } has issues in it, print!\n"
254
254
  print_status "#{ _tag }", BLUE
255
255
  cprint "\n"
@@ -261,8 +261,8 @@ module Watson
261
261
 
262
262
 
263
263
  # Check to see if it has been resolved on GitHub/Bitbucket
264
- debug_print "Checking if issue has been resolved\n"
265
- @config.github_issues[:closed].each do | _closed |
264
+ debug_print "Checking if issue has been resolved\n"
265
+ @config.github_issues[:closed].each do | _closed |
266
266
  if _closed["body"].include?(_issue[:md5])
267
267
  debug_print "Found in #{ _closed[:comment] }, not posting\n"
268
268
  cprint BOLD + " [" + RESET
@@ -270,10 +270,10 @@ module Watson
270
270
  cprint BOLD + "]" + RESET
271
271
  end
272
272
  debug_print "Did not find in #{ _closed[:comment] }\n"
273
- end
273
+ end
274
274
 
275
275
  debug_print "Checking if issue has been resolved\n"
276
- @config.bitbucket_issues[:closed].each do | _closed |
276
+ @config.bitbucket_issues[:closed].each do | _closed |
277
277
  if _closed["content"].include?(_issue[:md5])
278
278
  debug_print "Found in #{ _closed["content"] }, not posting\n"
279
279
  cprint BOLD + " [" + RESET
@@ -288,6 +288,6 @@ module Watson
288
288
  cprint "\n"
289
289
  end
290
290
  end
291
-
291
+
292
292
  end
293
- end
293
+ end
data/lib/watson/remote.rb CHANGED
@@ -1,23 +1,23 @@
1
1
  module Watson
2
- # Remote class that handles all remote HTTP calls to Bitbucket and GitHub
2
+ # Remote class that handles all remote HTTP calls to Bitbucket and GitHub
3
3
  class Remote
4
4
 
5
5
  # Debug printing for this class
6
- DEBUG = false
7
-
6
+ DEBUG = false
7
+
8
8
  class << self
9
-
9
+
10
10
  # Include for debug_print
11
11
  include Watson
12
12
 
13
- # Required libs
13
+ # Required libs
14
14
  require 'net/https'
15
15
  require 'uri'
16
16
  require 'json'
17
-
18
-
17
+
18
+
19
19
  # Default options hash for http_call
20
- # Will get merged with input argument hash to maintain defaults
20
+ # Will get merged with input argument hash to maintain defaults
21
21
  HTTP_opts = {
22
22
  :url => nil, #--> URL of endpoint [String]
23
23
  :ssl => false, #--> Use SSL in connection (HTTPS) (True/False]
@@ -28,36 +28,36 @@ module Watson
28
28
  :data => nil, #--> Hash of data to be POST'd in HTTP request [Hash]
29
29
  :verbose => false #--> Turn on verbose debug for this call [True/False]
30
30
  }
31
-
31
+
32
32
  ###########################################################
33
33
  # Generic HTTP call method
34
- # Accepts input hash of options that dictate how the HTTP call is to be made
34
+ # Accepts input hash of options that dictate how the HTTP call is to be made
35
35
  def http_call( opts )
36
36
  # [review] - Don't use DEBUG inside Remote class but pull from calling method's class?
37
37
  # [review] - Not sure if this is the best/proper way to do things but it works...
38
38
 
39
39
  # Identify method entry
40
40
  debug_print "#{ self.class } : #{ __method__ }\n"
41
-
41
+
42
42
  # Merge default options with those passed in by user to form complete opt list
43
43
  opts = HTTP_opts.merge(opts)
44
44
 
45
45
 
46
46
  # Check URL in hash and get URI from it, then set up HTTP connection
47
47
  if opts[:url] =~ /^#{URI::regexp}$/
48
- _uri = URI(opts[:url])
48
+ _uri = URI(opts[:url])
49
49
  else
50
50
  debug_print "No URL specified in input opts, exiting HTTP call\n"
51
51
  return false
52
52
  end
53
-
53
+
54
54
  _http = Net::HTTP.new(_uri.host, _uri.port)
55
-
55
+
56
56
  # Print out verbose HTTP request if :verbose is set
57
57
  # For hardcore debugging when shit really doesn't work
58
58
  _http.set_debug_output $stderr if opts[:verbose] == true
59
-
60
- # If SSL is set in hash, set HTTP connection to use SSL
59
+
60
+ # If SSL is set in hash, set HTTP connection to use SSL
61
61
  _http.use_ssl = true if opts[:ssl] == true
62
62
 
63
63
  # Create request based on HTTP method
@@ -65,10 +65,10 @@ module Watson
65
65
  case opts[:method].upcase
66
66
  when "GET"
67
67
  _req = Net::HTTP::Get.new(_uri.request_uri)
68
-
68
+
69
69
  when "POST"
70
70
  _req = Net::HTTP::Post.new(_uri.request_uri)
71
-
71
+
72
72
  else
73
73
  debug_print "No method specified, cannot make HTTP request\n"
74
74
  return false
@@ -77,7 +77,7 @@ module Watson
77
77
  # Check for basic authentication key in hash
78
78
  if opts[:basic_auth].size == 2
79
79
  _req.basic_auth(opts[:basic_auth][0], opts[:basic_auth][1])
80
- end
80
+ end
81
81
 
82
82
  # Check for Authentication token key in hash to be used in header
83
83
  # I think this is pretty universal, but specifically works for GitHub
@@ -86,9 +86,9 @@ module Watson
86
86
  end
87
87
 
88
88
  # [review] - Add :data_format to use set_form_data vs json body?
89
- # For now, use Hash or Array, this is to differentiate between
89
+ # For now, use Hash or Array, this is to differentiate between
90
90
  # putting post data in body vs putting it in the form
91
-
91
+
92
92
  # If a POST method, :data is present, and is a Hash, fill request body with data
93
93
  if opts[:method].upcase == "POST" && opts[:data] && opts[:data].is_a?(Hash)
94
94
  _req.body = opts[:data].to_json
@@ -106,14 +106,14 @@ module Watson
106
106
  debug_print "HTTP Response Code: #{ _resp.code }\n"
107
107
  debug_print "HTTP Response Msg: #{ _resp.message }\n"
108
108
 
109
- # [fix] - Not sure if 401 is the only code that gives nonparseable body?
109
+ # [fix] - Not sure if 401 is the only code that gives nonparseable body?
110
110
  # Figure out what other response codes are bad news for JSON.parse
111
111
  _json = _resp.code == "401" ? Hash.new : JSON.parse(_resp.body)
112
112
  debug_print "JSON: \n #{ _json }\n"
113
113
 
114
114
  # [review] - Returning hash of json + response the right thing to do?
115
115
  # return {:json => _json, :resp => _resp}
116
- return _json, _resp
116
+ return _json, _resp
117
117
  end
118
118
  end
119
119
  end
@@ -1,3 +1,3 @@
1
- module Watson
2
- VERSION = "1.0.5"
1
+ module Watson
2
+ VERSION = "1.0.6"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe Config do
16
16
 
17
17
  describe '#create_conf' do
18
18
  it 'create config file, return true' do
19
- @config.create_conf.should be_true
19
+ @config.create_conf.should be_true
20
20
  File.exists?(@file).should be_true
21
21
  end
22
22
  end
@@ -35,7 +35,7 @@ describe Config do
35
35
  File.exists?(@file).should be_true
36
36
  end
37
37
  end
38
- end
38
+ end
39
39
 
40
40
  describe '#read_conf' do
41
41
  context 'config does not exist' do
@@ -53,24 +53,24 @@ describe Config do
53
53
  @config.dir_list.should include('.')
54
54
  @config.tag_list.should include('fix', 'review', 'todo')
55
55
  @config.ignore_list.should include('.git', '*.swp')
56
-
56
+
57
57
  end
58
58
  end
59
59
  end
60
60
 
61
61
  describe '#update_conf' do
62
- before do
62
+ before do
63
63
  @config.check_conf
64
- @config.parse_depth = 1000
65
- @config.update_conf('parse_depth')
66
- end
64
+ @config.parse_depth = 1000
65
+ @config.update_conf('parse_depth')
66
+ end
67
67
 
68
68
  it 'updated config.parse_depth should be 1000' do
69
69
  @new_config = Config.new
70
70
  @new_config.check_conf.should be_true
71
71
  @new_config.read_conf.should be_true
72
72
  @new_config.parse_depth.to_i.should eql 1000
73
- end
73
+ end
74
74
  end
75
75
 
76
76
  # [review] - Should this be #initialize or #new?
@@ -81,7 +81,7 @@ describe Config do
81
81
  @config.cl_ignore_set.should be_false
82
82
 
83
83
  @config.use_less.should be_false
84
-
84
+
85
85
  @config.ignore_list.should == []
86
86
  @config.dir_list.should == []
87
87
  @config.file_list.should == []
@@ -101,7 +101,7 @@ describe Config do
101
101
  @config.bitbucket_issues.should == {:open => Hash.new(),
102
102
  :closed => Hash.new() }
103
103
 
104
- end
104
+ end
105
105
  end
106
106
 
107
107
  describe '#run' do
@@ -110,7 +110,7 @@ describe Config do
110
110
  @config.ignore_list.should include('.git', '*.swp')
111
111
  @config.tag_list.should include('fix', 'review', 'todo')
112
112
  @config.dir_list.should include('.')
113
- end
113
+ end
114
114
 
115
115
  end
116
116
 
data/spec/fs_spec.rb CHANGED
@@ -29,7 +29,7 @@ describe FS do
29
29
  FS.check_file('spec/fs_spec.rb').should be_true
30
30
  end
31
31
  end
32
- end
32
+ end
33
33
 
34
34
  describe '.check_dir' do
35
35
  context 'blank input dir' do
data/spec/helper_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # [review] - Using own funky path loading because traditional way seems wrong?
2
- # Commented out version is traditional, seen in many apps. If you use that and
2
+ # Commented out version is traditional, seen in many apps. If you use that and
3
3
  # look at load_path you get path/../lib (I'd expect those to be separate?)
4
4
  # My funky version adds path/., path/bin, path/assets separately
5
5
  # Maybe I don't get how the load path is supposed to look though...
data/spec/parser_spec.rb CHANGED
@@ -18,16 +18,80 @@ describe Parser do
18
18
 
19
19
  describe '#get_comment_type' do
20
20
  context 'known extension' do
21
- it 'return correct extension (# for ruby)' do
22
- @parser.get_comment_type('lib/watson.rb').should eql '#'
21
+ it 'return correct extension for c++' do
22
+ @parser.get_comment_type('lib/watson.cpp').should eql ['//', '/*']
23
+ @parser.get_comment_type('lib/watson.cc').should eql ['//', '/*']
24
+ @parser.get_comment_type('lib/watson.hpp').should eql ['//', '/*']
25
+ @parser.get_comment_type('lib/watson.c').should eql ['//', '/*']
26
+ @parser.get_comment_type('lib/watson.h').should eql ['//', '/*']
23
27
  end
24
28
 
25
- it 'return correct extension (# for coffee)' do
26
- @parser.get_comment_type('lib/watson.coffee').should eql '#'
29
+ it 'return correct extension for java' do
30
+ @parser.get_comment_type('lib/watson.java').should eql ['//', '/*', '/**']
31
+ @parser.get_comment_type('lib/watson.class').should eql ['//', '/*', '/**']
27
32
  end
28
33
 
29
- it 'return correct extension (// for c/c++)' do
30
- @parser.get_comment_type('lib/watson.cpp').should eql '//'
34
+ it 'return correct extension for csharp' do
35
+ @parser.get_comment_type('lib/watson.cs').should eql ['//', '/*']
36
+ end
37
+
38
+ it 'return correct extension for javascript' do
39
+ @parser.get_comment_type('lib/watson.js').should eql ['//', '/*']
40
+ end
41
+
42
+ it 'return correct extension for php' do
43
+ @parser.get_comment_type('lib/watson.php').should eql ['//', '/*', '#']
44
+ end
45
+
46
+ it 'return correct extension for objectivec' do
47
+ @parser.get_comment_type('lib/watson.m').should eql ['//', '/*']
48
+ @parser.get_comment_type('lib/watson.mm').should eql ['//', '/*']
49
+ end
50
+
51
+ it 'return correct extension for go' do
52
+ @parser.get_comment_type('lib/watson.go').should eql ['//', '/*']
53
+ end
54
+
55
+ it 'return correct extension for scala' do
56
+ @parser.get_comment_type('lib/watson.scala').should eql ['//', '/*']
57
+ end
58
+
59
+ it 'return correct extension for erlang' do
60
+ @parser.get_comment_type('lib/watson.erl').should eql ['%%', '%']
61
+ end
62
+
63
+ it 'return correct extension haskell' do
64
+ @parser.get_comment_type('lib/watson.hs').should eql ['--']
65
+ end
66
+
67
+ it 'return correct extension bash' do
68
+ @parser.get_comment_type('lib/watson.sh').should eql ['#']
69
+ end
70
+
71
+ it 'return correct extension ruby' do
72
+ @parser.get_comment_type('lib/watson.rb').should eql ['#']
73
+ end
74
+
75
+ it 'return correct extension perl' do
76
+ @parser.get_comment_type('lib/watson.pl').should eql ['#']
77
+ @parser.get_comment_type('lib/watson.pm').should eql ['#']
78
+ @parser.get_comment_type('lib/watson.t').should eql ['#']
79
+ end
80
+
81
+ it 'return correct extension python' do
82
+ @parser.get_comment_type('lib/watson.py').should eql ['#']
83
+ end
84
+
85
+ it 'return correct extension coffeescript' do
86
+ @parser.get_comment_type('lib/watson.coffee').should eql ['#']
87
+ end
88
+
89
+ it 'return correct extension zsh' do
90
+ @parser.get_comment_type('lib/watson.zsh').should eql ['#']
91
+ end
92
+
93
+ it 'return correct extension (;; for clojure)' do
94
+ @parser.get_comment_type('lib/watson.clj').should eql [';;']
31
95
  end
32
96
  end
33
97
 
@@ -72,7 +136,7 @@ describe Parser do
72
136
  FileUtils.mkdir('test_dir')
73
137
  FileUtils.cp('assets/examples/main.cpp', 'test_dir/')
74
138
  end
75
-
139
+
76
140
  it 'generate populated hash structure from file' do
77
141
  @structure = @parser.parse_file('test_dir/main.cpp')
78
142
 
@@ -85,7 +149,7 @@ describe Parser do
85
149
  FileUtils.rm_rf('test_dir')
86
150
  end
87
151
  end
88
-
152
+
89
153
  end
90
154
 
91
155
  describe '#parse_dir' do
@@ -112,7 +176,7 @@ describe Parser do
112
176
  FileUtils.mkdir('test_dir')
113
177
  FileUtils.cp('assets/examples/main.cpp', 'test_dir/')
114
178
  end
115
-
179
+
116
180
  it 'generate hash structure with parsed file' do
117
181
  @structure = @parser.parse_dir('test_dir/', 0)
118
182
  @structure[:files][0][:relative_path].should == 'test_dir/main.cpp'