Module: Box::Release::Base
- Included in:
- Memory
- Defined in:
- lib/box/release/base.rb
Instance Method Summary collapse
-
#download ⇒ Object
def presenter @presenter ||= ReleasePresenter.new self end.
-
#file ⇒ Object
def status=(status, update_timestamp = true) write_attribute :status, status ? status.to_s : nil self.status_updated_at = Time.now unless new_record? end.
- #file_checksum ⇒ Object
- #file_exists? ⇒ Boolean
-
#install(options = {}) ⇒ Object
self end.
- #newer?(other) ⇒ Boolean
- #to_yaml ⇒ Object
- #valid_checksum? ⇒ Boolean
- #yaml_file ⇒ Object
Instance Method Details
#download ⇒ Object
def presenter
@presenter ||= ReleasePresenter.new self
end
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/box/release/base.rb', line 76 def download logger.info "Download #{url} into #{file}" # return if self.status.downloaded? # update_attribute :status, :download_pending File.open(file, "w") do |file| Box::Release::Downloader.open(url) do |data, download_size, url_size| file.write data # self.url_size ||= url_size # self.download_size = download_size # save! if 10.seconds.ago > self.updated_at end end raise "Invalid checksum after download" unless valid_checksum? # self.status = :downloaded ensure # self.status = :download_failed unless self.status.downloaded? # save! end |
#file ⇒ Object
def status=(status, update_timestamp = true)
write_attribute :status, status ? status.to_s : nil
self.status_updated_at = Time.now unless new_record?
end
64 65 66 |
# File 'lib/box/release/base.rb', line 64 def file "/tmp/release.tar" end |
#file_checksum ⇒ Object
135 136 137 |
# File 'lib/box/release/base.rb', line 135 def file_checksum Digest::SHA256.file(file).hexdigest if file_exists? end |
#file_exists? ⇒ Boolean
139 140 141 |
# File 'lib/box/release/base.rb', line 139 def file_exists? File.exists?(file) end |
#install(options = {}) ⇒ Object
self end
110 111 112 113 114 115 116 117 |
# File 'lib/box/release/base.rb', line 110 def install( = {}) = { :install_command => install_command }.merge() logger.info "Install #{name}" Box::Release.execute! "#{[:install_command]} #{file} #{yaml_file}" end |
#newer?(other) ⇒ Boolean
68 69 70 |
# File 'lib/box/release/base.rb', line 68 def newer?(other) other.nil? or (self.name and self.name > other.name) end |
#to_yaml ⇒ Object
143 144 145 |
# File 'lib/box/release/base.rb', line 143 def to_yaml { "name" => name, "description_url" => description_url, "status_updated_at" => status_updated_at }.to_yaml end |
#valid_checksum? ⇒ Boolean
131 132 133 |
# File 'lib/box/release/base.rb', line 131 def valid_checksum? checksum.nil? or checksum == file_checksum end |
#yaml_file ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/box/release/base.rb', line 119 def yaml_file @yaml_file ||= Tempfile.new("release").tap do |yaml_file| begin yaml_file.write to_yaml ensure yaml_file.close end end @yaml_file.path end |