Class: Tractive::Utilities
- Inherits:
-
Object
- Object
- Tractive::Utilities
- Defined in:
- lib/tractive/utilities.rb
Class Method Summary collapse
- .attachment_path(id, filename, options = {}) ⇒ Object
- .dasharize(str) ⇒ Object
- .make_each_hash(values, keys, prefix = "") ⇒ Object
- .make_hash(prefix, array) ⇒ Object
-
.map_changeset(str, revmap, changeset_base_url = "") ⇒ Object
returns the git commit hash for a specified revision (using revmap hash).
- .setup_db!(db_url) ⇒ Object
- .setup_logger(options = {}) ⇒ Object
- .svn_log(url, local_path, flags = {}) ⇒ Object
Class Method Details
.attachment_path(id, filename, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tractive/utilities.rb', line 43 def (id, filename, = {}) return "#{id}/#{filename}" unless [:hashed] folder_name = Digest::SHA1.hexdigest(id) parent_folder_name = folder_name[0..2] hashed_filename = Digest::SHA1.hexdigest(filename) file_extension = File.extname(filename) "#{parent_folder_name}/#{folder_name}/#{hashed_filename}#{file_extension}" end |
.dasharize(str) ⇒ Object
39 40 41 |
# File 'lib/tractive/utilities.rb', line 39 def dasharize(str) str.gsub(/([a-z\d])([A-Z])/, '\1-\2').downcase end |
.make_each_hash(values, keys, prefix = "") ⇒ Object
10 11 12 13 14 15 |
# File 'lib/tractive/utilities.rb', line 10 def make_each_hash(values, keys, prefix = "") values.map do |value| value = [value] unless value.is_a?(Array) [value[0], keys.zip(value.map { |v| "#{prefix}#{v}" }).to_h] end.to_h end |
.make_hash(prefix, array) ⇒ Object
6 7 8 |
# File 'lib/tractive/utilities.rb', line 6 def make_hash(prefix, array) array.map { |i| [i, "#{prefix}#{i}"] }.to_h end |
.map_changeset(str, revmap, changeset_base_url = "") ⇒ Object
returns the git commit hash for a specified revision (using revmap hash)
64 65 66 67 68 69 70 71 72 |
# File 'lib/tractive/utilities.rb', line 64 def map_changeset(str, revmap, changeset_base_url = "") if revmap&.key?(str) && !revmap[str].nil? base_url = changeset_base_url base_url += "/" if base_url[-1] && base_url[-1] != "/" "#{base_url}#{revmap[str].strip}" else "[#{str}]" end end |
.setup_db!(db_url) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tractive/utilities.rb', line 17 def setup_db!(db_url) files_to_load = [ "lib/tractive/models/attachment.rb", "lib/tractive/models/milestone.rb", "lib/tractive/models/report.rb", "lib/tractive/models/revision.rb", "lib/tractive/models/session.rb", "lib/tractive/models/ticket_change.rb", "lib/tractive/models/ticket.rb", "lib/tractive/models/wiki.rb" ] db = Sequel.connect(db_url) if db_url raise("could not connect to tractive database") unless db files_to_load.each do |file| require_relative "../../#{file}" end db end |
.setup_logger(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/tractive/utilities.rb', line 54 def setup_logger( = {}) $logger = Logger.new([:output_stream]) $logger.level = [:verbose] ? Logger::DEBUG : Logger::INFO $logger.formatter = proc do |severity, datetime, _progname, msg| time = datetime.strftime("%Y-%m-%d %H:%M:%S") "[#{time}] #{severity}#{" " * (5 - severity.size + 1)}| #{msg}\n" end end |
.svn_log(url, local_path, flags = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tractive/utilities.rb', line 74 def svn_log(url, local_path, flags = {}) command = "svn log" command += " #{url}" if url flags.each do |key, value| command += " #{key}" command += " #{value}" if value end if local_path Dir.chdir(local_path) do `#{command}` end else `#{command}` end end |