Class: RSUtils
- Inherits:
-
Object
- Object
- RSUtils
- Defined in:
- lib/rsite/utils.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#current ⇒ Object
Returns the value of attribute current.
-
#firstrun ⇒ Object
Returns the value of attribute firstrun.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #clear_current ⇒ Object
- #directory_hash ⇒ Object
- #files_to_update ⇒ Object
- #format_file_list(updateable, uri) ⇒ Object
-
#initialize(path) ⇒ RSUtils
constructor
A new instance of RSUtils.
- #save_uris(uri, ouri) ⇒ Object
- #serialize ⇒ Object
- #twopart_upload ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(path) ⇒ RSUtils
Returns a new instance of RSUtils.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rsite/utils.rb', line 12 def initialize(path) @filehashfilepath = File.join(path,'.filehashes') @inserturifilepath = File.join(path,'.inserturi') @ourifilepath = File.join(path,'.uri') @path = path @current ={} @version = 0 @firstrun = false directory_hash end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/rsite/utils.rb', line 10 def client @client end |
#current ⇒ Object
Returns the value of attribute current.
10 11 12 |
# File 'lib/rsite/utils.rb', line 10 def current @current end |
#firstrun ⇒ Object
Returns the value of attribute firstrun.
10 11 12 |
# File 'lib/rsite/utils.rb', line 10 def firstrun @firstrun end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/rsite/utils.rb', line 9 def path @path end |
#version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/rsite/utils.rb', line 10 def version @version end |
Instance Method Details
#clear_current ⇒ Object
23 24 25 |
# File 'lib/rsite/utils.rb', line 23 def clear_current @current = {} end |
#directory_hash ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rsite/utils.rb', line 27 def directory_hash Find.find(@path) do |p| Find.prune if File.split(p)[1][0] == '.' unless File.directory? p unless (p.include? @inserturifilepath or p.include? @filehashfilepath) or p.include? @ourifilepath @current[(Digest::SHA256.new << File.read(p)).base64digest] = p end end end end |
#files_to_update ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/rsite/utils.rb', line 38 def files_to_update last = YAML::load(File.read(@filehashfilepath)) unless @firstrun @version = last[0] if @version == 0 unless @firstrun if @firstrun @current.keys else @current.keys - last[1].keys end end |
#format_file_list(updateable, uri) ⇒ Object
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 |
# File 'lib/rsite/utils.rb', line 89 def format_file_list(updateable,uri) files = [] unless updateable.size == 0 updateable.each do |u| name = @current[u].sub @path, '' name.sub! '\\' '/' if File::SEPARATOR == '\\' name = name[1..-1] if name[0] == '/' file = {name: name, uploadfrom: 'disk', filename: @current[u]} unless @current[u] =~ /^CHK@/ file = {name: @current[u].split('/')[-1], uploadfrom: 'redirect', targeturi: @current[u]} if @current[u] =~ /^CHK@/ files.push file end end unless files.size == 0 (@current.keys - updateable).each do |u| name = @current[u].sub @path, '' name.sub! '\\' '/' if File::SEPARATOR == '\\' name = name[1..-1] if name[0] == '/' ssk = uri.split '@' ssk = 'SSK@'+(ssk[1].split('/')[0...-1].join('/'))+"-#{@version}/"+name file = {name: name, uploadfrom: 'redirect', targeturi: ssk} file = {name: @current[u].split('/')[-1], uploadfrom: 'redirect', targeturi: @current[u]} if @current[u] =~ /^CHK@/ files.push file end end files end |
#save_uris(uri, ouri) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rsite/utils.rb', line 48 def save_uris(uri,ouri) File.open(@inserturifilepath, 'w+') do |file| file.puts YAML::dump uri end File.open(@ourifilepath, 'w+') do |file| file.puts YAML::dump ouri end end |
#serialize ⇒ Object
57 58 59 60 61 62 |
# File 'lib/rsite/utils.rb', line 57 def serialize File.open(@filehashfilepath, 'w+') do |file| file.puts YAML::dump [@version, @current] end puts 'hashes stored in .filehashes' end |
#twopart_upload ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/rsite/utils.rb', line 79 def twopart_upload largerfiles = [] @current.each_key do |u| if (File.size @current[u]) > 1048576 largerfiles << u end end largerfiles end |
#update ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rsite/utils.rb', line 64 def update if File.exist? @filehashfilepath updateables = files_to_update return updateables else puts "Perform full upload to initialize the directory for use" if @firstrun updateables = files_to_update return updateables else return [] end end end |