Top Level Namespace
Defined Under Namespace
Modules: Radon
Constant Summary collapse
- VERSION =
The version
"0.1.8"
- PROJECT_ROOT =
The root of this project
File.absolute_path(File.join(File.dirname(__FILE__), "..", ".."))
- SETTINGS_DIR =
Settings pertaining to radon
File.join(Dir.home, '.periodic', 'radon')
- SETTINGS_FILE =
The settings json file
File.join(SETTINGS_DIR, 'settings.json')
- BASE_SETTINGS_DIR =
The base periodic settings path
File.join(Dir.home, '.periodic')
- DATA_DIR =
The folder containing zips and b64 files
File.absolute_path(File.join(PROJECT_ROOT, "data"))
- AUTHORS =
{ 'Carter Brainerd' => '0xCB[at]protonmail[dot]com' }
Instance Method Summary collapse
-
#ask(*args) ⇒ Object
Prompts the user for input.
-
#classify(name) ⇒ Object
Gets the project name in dash-seperated format.
- #create(fname) ⇒ Object
- #error(*args) ⇒ Object
- #extract_c(target) ⇒ Object
- #extract_crystal(target) ⇒ Object
- #extract_go_s(target) ⇒ Object
- #extract_gradle(target) ⇒ Object
- #extract_java(target) ⇒ Object
- #extract_maven(target) ⇒ Object
- #extract_python(target) ⇒ Object
- #extract_ruby(target) ⇒ Object
- #extract_website(target) ⇒ Object
-
#extract_zip(file, destination) ⇒ Object
Extracts some zip data to the passed destination.
- #fail_with(reason) ⇒ Object
-
#find_and_replace_all(target_dir, find, repl) ⇒ Object
Replaces ‘find’ with ‘repl’ in every file and directory.
-
#projectify(name) ⇒ Object
Gets the project name in capitalized format.
-
#replace_all_tokens(target) ⇒ Object
Replaces all tokens in all files in the target directory.
- #report_error_to_github(trace) ⇒ Object
- #skip(fname) ⇒ Object
- #vprint(*args) ⇒ Object
Instance Method Details
#ask(*args) ⇒ Object
Prompts the user for input
66 67 68 69 |
# File 'lib/core/text.rb', line 66 def ask(*args) print(*args) $stdin.gets.chomp end |
#classify(name) ⇒ Object
Gets the project name in dash-seperated format. Eg: my-project-name
72 73 74 75 76 |
# File 'lib/core/text.rb', line 72 def classify(name) name = name.gsub(/-[a-z]/) {|s| s.upcase } name.delete!('-') return name.slice(0,1).capitalize + name.slice(1..-1) end |
#create(fname) ⇒ Object
43 44 45 |
# File 'lib/core/text.rb', line 43 def create(fname) puts Paint[' create', '#2ecc71'] + " #{fname}" unless $quiet end |
#error(*args) ⇒ Object
7 8 9 |
# File 'lib/core/text.rb', line 7 def error(*args) puts Paint['ERROR', '#e74c3c'] + " - #{args.join(' ')}" end |
#extract_c(target) ⇒ Object
26 27 28 |
# File 'lib/core/extract.rb', line 26 def extract_c(target) extract_zip(Radon::Environments.get_target_of('c'), target) end |
#extract_crystal(target) ⇒ Object
30 31 32 33 |
# File 'lib/core/extract.rb', line 30 def extract_crystal(target) extract_zip(Radon::Environments.get_target_of('crystal'), target) replace_all_tokens(target) end |
#extract_go_s(target) ⇒ Object
35 36 37 |
# File 'lib/core/extract.rb', line 35 def extract_go_s(target) extract_zip(Radon::Environments.get_target_of('go_s'), target) end |
#extract_gradle(target) ⇒ Object
5 6 7 |
# File 'lib/core/extract.rb', line 5 def extract_gradle(target) extract_zip(Radon::Environments.get_target_of('gradle'), target) end |
#extract_java(target) ⇒ Object
9 10 11 |
# File 'lib/core/extract.rb', line 9 def extract_java(target) extract_zip(Radon::Environments.get_target_of('java'), target) end |
#extract_maven(target) ⇒ Object
13 14 15 |
# File 'lib/core/extract.rb', line 13 def extract_maven(target) extract_zip(Radon::Environments.get_target_of('maven'), target) end |
#extract_python(target) ⇒ Object
17 18 19 |
# File 'lib/core/extract.rb', line 17 def extract_python(target) extract_zip(Radon::Environments.get_target_of('python'), target) end |
#extract_ruby(target) ⇒ Object
21 22 23 24 |
# File 'lib/core/extract.rb', line 21 def extract_ruby(target) extract_zip(Radon::Environments.get_target_of('ruby'), target) replace_all_tokens(target) end |
#extract_website(target) ⇒ Object
39 40 41 |
# File 'lib/core/extract.rb', line 39 def extract_website(target) extract_zip(Radon::Environments.get_target_of('website'), target) end |
#extract_zip(file, destination) ⇒ Object
Extracts some zip data to the passed destination
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/core/extract.rb', line 44 def extract_zip(file, destination) puts "Creating project under #{File.(destination)}" unless $quiet create(destination) FileUtils.mkdir_p(destination) Zip::File.open(file) do |zip_file| zip_file.each do |f| fname = f.name.gsub('{{NAME}}', projectify(destination)) fpath = File.join(destination, fname) if File.exists?(fpath) skip(fpath) else create(fpath) end zip_file.extract(f, fpath) unless File.exist?(fpath) end end end |
#fail_with(reason) ⇒ Object
68 69 70 71 |
# File 'lib/core/util.rb', line 68 def fail_with(reason) error(reason) exit 1 end |
#find_and_replace_all(target_dir, find, repl) ⇒ Object
Replaces ‘find’ with ‘repl’ in every file and directory
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/core/text.rb', line 79 def find_and_replace_all(target_dir, find, repl) files = Dir[File.join(target_dir,'**','*')] files.each do |file_name| next if File.directory?(file_name) begin text = File.read(file_name) # Do the find and replace new_contents = text.gsub(find, repl) File.open(file_name, 'w') {|f| f.puts new_contents} rescue Errno::ENOENT => e # Something weird happened (this shouldn't come up) error "ERROR GSUBING FILE #{file_name}" report_error_to_github(e.backtrace) next end end end |
#projectify(name) ⇒ Object
Gets the project name in capitalized format. Eg: MyProjectName
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/core/text.rb', line 52 def projectify(name) # Name becomes frozen for some reason name = name.gsub(/(.)([A-Z])/, '\1-\2') name.downcase! name.gsub!('..', '') name.gsub!('/', '') name.gsub!('\\', '') name[0] = '' if name[0] == '-' name.gsub!('--', '-') name.gsub!('_-', '-') return name end |
#replace_all_tokens(target) ⇒ Object
Replaces all tokens in all files in the target directory
98 99 100 101 102 103 |
# File 'lib/core/text.rb', line 98 def replace_all_tokens(target) find_and_replace_all(target, '{{NAME}}', projectify(target)) find_and_replace_all(target, '{{CAPSNAME}}', classify(target)) find_and_replace_all(target, '{{EMAIL}}', Radon::Util.get_email) find_and_replace_all(target, '{{GHNAME}}', Radon::Util.get_github_username) end |
#report_error_to_github(trace) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/core/text.rb', line 11 def report_error_to_github(trace) commit_string = File.directory?(File.join(PROJECT_ROOT, '.git')) ? "Commit `#{File.read(File.join(PROJECT_ROOT, '.git', 'refs', 'heads', 'master')).strip}`" : nil puts %( :::::::::::::::::: COPY BELOW :::::::::::::::::: ### Ruby version `#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}` ### OS #{Gem::Platform.local.os} ### Radon Version `VERSION` ### Date Found #{Time.now.strftime("%d/%m/%Y %H:%M")} ### Backtrace ``` #{trace} ``` #{commit_string} :::::::::::::::::: COPY ABOVE :::::::::::::::::: #{Paint["Whoops! Looks like you've found a bug in radon. Please copy the text above and open a new issue at ", '#e74c3c'] + Paint['https://github.com/cbrnrd/radon/issues', :bold, :bright]} ) end |
#skip(fname) ⇒ Object
47 48 49 |
# File 'lib/core/text.rb', line 47 def skip(fname) puts Paint[' skip', '#f1c40f'] + " #{fname}" unless $quiet end |
#vprint(*args) ⇒ Object
3 4 5 |
# File 'lib/core/text.rb', line 3 def vprint(*args) puts args if $verbose && !$quiet end |