Module: CoderCompanion
- Defined in:
- lib/codercompanion.rb,
lib/codercompanion/api.rb,
lib/codercompanion_version.rb,
lib/codercompanion/java/java.rb,
lib/codercompanion/languages.rb,
lib/codercompanion/s3_client.rb,
lib/codercompanion/tree_walker.rb,
lib/codercompanion/cachehandler.rb,
lib/codercompanion/common/common.rb,
lib/codercompanion/cpp/cpp_parser.rb,
lib/codercompanion/parser_factory.rb,
lib/codercompanion/common/literals.rb,
lib/codercompanion/language_parser.rb,
lib/codercompanion/java/java_parser.rb,
lib/codercompanion/ruby/ruby_parser.rb,
lib/codercompanion/cpp/cpp_tree_walker.rb,
lib/codercompanion/java/java_tree_walker.rb,
lib/codercompanion/ruby/ruby_annotations.rb,
lib/codercompanion/ruby/ruby_tree_walker.rb,
lib/codercompanion/codercompanion_exception.rb
Defined Under Namespace
Modules: Common, Cpp, Java, Languages, Ruby
Classes: API, CacheHandler, CoderCompanionException, LanguageParser, ParserFactory, S3Client, TreeWalker
Constant Summary
collapse
- BASEPATH =
File.expand_path('..', File.dirname(__FILE__) )
- STATUS_OK =
200
- USER_NOT_FOUND =
461
- PROJECT_NOT_FOUND =
510
- GENERIC_ERROR =
500
- CONFIG_FILE_NAME =
'codercmp.conf'
- VERSION =
'0.9.7'
- @@options =
{}
- @@config =
nil
- @@visit_config_location_message =
""
- @@src_folder =
""
- @@api =
CoderCompanion::API.new
Class Method Summary
collapse
Class Method Details
.annotation ⇒ String
174
175
176
|
# File 'lib/codercompanion.rb', line 174
def self.annotation
@@annotation
end
|
.annotation=(annotation) ⇒ Object
179
180
181
|
# File 'lib/codercompanion.rb', line 179
def self.annotation=(annotation)
@@annotation = annotation
end
|
.base_path ⇒ Object
117
118
119
|
# File 'lib/codercompanion.rb', line 117
def self.base_path
BASEPATH
end
|
130
131
132
|
# File 'lib/codercompanion.rb', line 130
def self.cache_handler
@@cache_handler
end
|
.config ⇒ Object
159
160
161
|
# File 'lib/codercompanion.rb', line 159
def self.config
@@config
end
|
.display_supported_languages ⇒ Object
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'lib/codercompanion.rb', line 290
def self.display_supported_languages
languages = CoderCompanion::Languages.supported_languages
puts "---------------------------------------------------------------------------------------------\n\n \#{CoderCompanion::notification_format(\"CoderCompanion Supported Languages (2015-05-30)\")}\n\n---------------------------------------------------------------------------------------------\n"
languages.each do |lang|
puts "\n Language: \#{CoderCompanion::notification_format(lang[:key])}\\t\\t|\\t Requires Annotations: \#{lang[:annotation_required] ? CoderCompanion::success_format(\"YES\") : CoderCompanion::red_format(\"NO\") }\\t\\t|\\tAnnotations Style(s): \#{(lang[:annotation_required]) ? CoderCompanion::notification_format(lang[:valid_annotation].join(\", \")) : CoderCompanion::notification_format(\"N/A\")}\n \n"
end
end
|
.dry_run? ⇒ Boolean
135
136
137
|
# File 'lib/codercompanion.rb', line 135
def self.dry_run?
@@options[:dry_run]
end
|
194
195
196
|
# File 'lib/codercompanion.rb', line 194
def self.error_format(string)
return CoderCompanion.no_color ? string : string.white_on_red.bold
end
|
199
200
201
|
# File 'lib/codercompanion.rb', line 199
def self.error_url_format(string)
return CoderCompanion.no_color ? string : string.yellow_on_red.bold.underline
end
|
.excluded ⇒ Object
154
155
156
|
# File 'lib/codercompanion.rb', line 154
def self.excluded
@@options[:exclude]
end
|
.fresh_run ⇒ Boolean
145
146
147
|
# File 'lib/codercompanion.rb', line 145
def self.fresh_run
@@options[:fresh_run]
end
|
.init ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/codercompanion.rb', line 63
def self.init
j_print "-----------------------------------------------------------------------------------------------\n\n \#{special_format(\"R u n n i n g C o d e r C o m p a n i o n u p l o a d e r\")}\n \n-----------------------------------------------------------------------------------------------\n"
@@visit_config_location_message = error_format("Please visit ") + error_url_format("http://codercompanion.com") + error_format(" for more info")
config_filename = @@options[:config_file] ? @@options[:config_file] : "#{CONFIG_FILE_NAME}"
file = nil
begin
file = File.open(config_filename)
rescue => e
j_print e.to_s
raise CoderCompanionException.new(error_format("An error occured while trying to open the configuration file"))
end
begin
@@config = JSON.parse(file.read)
rescue => e
j_print error_format e.to_s
raise CoderCompanionException.new(error_format("could not parse your config file. ") + @@visit_config_location_message)
end
verify_config_file
end
|
.j_print(string) ⇒ Object
121
122
123
|
# File 'lib/codercompanion.rb', line 121
def self.j_print(string)
puts string if !silent_run
end
|
.j_print_inline(string) ⇒ Object
125
126
127
|
# File 'lib/codercompanion.rb', line 125
def self.j_print_inline(string)
print string if !silent_run
end
|
.language ⇒ String
164
165
166
|
# File 'lib/codercompanion.rb', line 164
def self.language
@@language
end
|
.language=(language) ⇒ Object
169
170
171
|
# File 'lib/codercompanion.rb', line 169
def self.language=(language)
@@language = language
end
|
.no_color ⇒ Boolean
150
151
152
|
# File 'lib/codercompanion.rb', line 150
def self.no_color
@@options[:no_color]
end
|
209
210
211
|
# File 'lib/codercompanion.rb', line 209
def self.notification_format(string)
return CoderCompanion.no_color ? string : string.yellow_on_black
end
|
.pretty_inspect(thing) ⇒ Object
282
283
284
285
286
287
288
|
# File 'lib/codercompanion.rb', line 282
def self.pretty_inspect(thing)
begin
thing.awesome_inspect
rescue
thing.inspect
end
end
|
204
205
206
|
# File 'lib/codercompanion.rb', line 204
def self.red_format(string)
return CoderCompanion.no_color ? string : string.red_on_black.bold
end
|
.run ⇒ Object
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/codercompanion.rb', line 310
def self.run
if self.dry_run?
j_print "\n\#{notification_format(\"Performing dry run:\")}\n- No cache use\n- No upload \n\n"
end
@@cache_handler = CacheHandler.new
@@cache_handler.load_cache(fresh_run)
p = CoderCompanion::ParserFactory.get_parser(self.language)
uploadable = p.create_project_json(@@src_folder)
if @@options[:show_output]
ap uploadable
end
if !uploadable
j_print error_format("Something went wrong while trying to create uploadable")
return
end
if !self.dry_run?
file_rel_path = './test_upload.codercompanion'
File.open(file_rel_path, 'w+') {|f| f.write(uploadable.to_json) }
j_print notification_format("uploading to #{@@config["host"]}...")
upload(file_rel_path)
File.delete(file_rel_path)
self.cache_handler.write_cached_data
j_print success_format("Uploaded your changes successfully")
end
end
|
.silent_run ⇒ Boolean
140
141
142
|
# File 'lib/codercompanion.rb', line 140
def self.silent_run
@@options[:silent_run]
end
|
184
185
186
|
# File 'lib/codercompanion.rb', line 184
def self.special_format(string)
return CoderCompanion.no_color ? string : string.white_on_black.bold
end
|
.start(options, location) ⇒ Object
401
402
403
404
405
406
407
408
|
# File 'lib/codercompanion.rb', line 401
def self.start(options, location)
@@options = options
@@src_folder = location
self.init
self.run
end
|
214
215
216
|
# File 'lib/codercompanion.rb', line 214
def self.success_format(string)
return CoderCompanion.no_color ? string : string.green_on_black.bold
end
|
.upload(file) ⇒ Object
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
# File 'lib/codercompanion.rb', line 364
def self.upload(file)
response = @@api.get_temporary_access_key
unless response
File.delete(file)
raise CoderCompanion::CoderCompanionException, "Failed to upload project"
end
response_data = JSON.parse(response)["data"]
credentials = response_data["credentials"]
region = response_data["region"]
s3_bucket = response_data["s3_bucket"]
s3_client = CoderCompanion::S3Client.new(
:session_token => credentials["session_token"],
:access_key_id => credentials["access_key_id"],
:secret_access_key => credentials["secret_access_key"],
:region => region,
:s3_bucket => s3_bucket
)
current_time = Time.now.utc.strftime("%Y-%m-%d:%H:%M:%S")
key = "#{@@config["user"]["access_id"]}/#{@@config["project"]["access_key"]}/#{current_time}/upload"
result = s3_client.put_object(file, key)
unless result
File.delete(file)
raise CoderCompanion::CoderCompanionException, "Failed to upload file to S3"
end
response = @@api.notify_s3_upload(key)
unless response
File.delete(file)
raise CoderCompanion::CoderCompanionException, "Failed to complete upload. It is possible our servers are down"
end
end
|
.verify_config_file ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/codercompanion.rb', line 218
def self.verify_config_file
j_print notification_format("Verifying Config file...")
error = false
if @@config
if @@config["project"]
if @@config["project"]["access_key"] == nil || @@config["project"]["access_key"].match(/^\s*$/)
j_print error_format("No access_key for project specified.")
error = true
end
is_supported = true
self.language = @@config["project"]["language"]
if self.language == nil || self.language.match(/^\s*$/)
j_print error_format("No language specified in your config file.")
error = true
elsif !CoderCompanion::Languages.is_supported?(self.language)
is_supported = false
j_print error_format("#{self.language} is not a supported language")
j_print notification_format("To see a list of supported languages run: \n\tcodercmp --language\n")
error = true
end
else
j_print error_format("Project not found in config file. ")
error = true
end
if @@config["user"]
if @@config["user"]["access_id"] == nil || @@config["user"]["access_id"] == ""
j_print error_format("No access_id for project specified.")
error = true
end
else
j_print error_format("User info not found")
error = true
end
if @@config["host"] == nil || @@config["host"] == ""
j_print error_format("Host not found")
error = true
end
end
if error
raise CoderCompanionException.new(@@visit_config_location_message)
end
j_print success_format("Config file Successfully Verified")
end
|
189
190
191
|
# File 'lib/codercompanion.rb', line 189
def self.warning_format(string)
return CoderCompanion.no_color ? string : string.black_on_yellow.bold
end
|