Class: OpenBuildServiceAPI::Binary
- Inherits:
-
Object
- Object
- OpenBuildServiceAPI::Binary
- Defined in:
- lib/models/binary.rb
Instance Attribute Summary collapse
-
#architecture ⇒ Object
readonly
Returns the value of attribute architecture.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#local_file_path ⇒ Object
readonly
Returns the value of attribute local_file_path.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
Returns the value of attribute package.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #delete_local_copy! ⇒ Object
- #download(destination = nil) ⇒ Object
-
#initialize(params = {}) ⇒ Binary
constructor
A new instance of Binary.
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Binary
Returns a new instance of Binary.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/models/binary.rb', line 6 def initialize(params = {}) raise ArgumentError.new('repository needs to be an instance of OpenBuildServiceAPI::Repository') unless params[:repository].is_a?(Repository) @name = params[:name] @size = Filesize.from(params[:size]) @created_at = Time.at(params[:created_at]) @repository = params[:repository] @architecture = params[:architecture] @package = params[:package] @connection = params[:connection] end |
Instance Attribute Details
#architecture ⇒ Object (readonly)
Returns the value of attribute architecture.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def architecture @architecture end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def created_at @created_at end |
#local_file_path ⇒ Object (readonly)
Returns the value of attribute local_file_path.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def local_file_path @local_file_path end |
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def local_path @local_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def name @name end |
#package ⇒ Object
Returns the value of attribute package.
4 5 6 |
# File 'lib/models/binary.rb', line 4 def package @package end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def repository @repository end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/models/binary.rb', line 3 def size @size end |
Instance Method Details
#delete_local_copy! ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/models/binary.rb', line 44 def delete_local_copy! return false unless @local_file_path return false unless File.exists?(@local_file_path) File.delete(@local_file_path) FileUtils.rm_r(@local_path) if Dir.empty?(@local_path) && @tmp_dir true end |
#download(destination = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/models/binary.rb', line 22 def download(destination=nil) delete_local_copy! if destination raise InvalidDownloadDirectoryPath.new("Path '#{destination}' is not a directory.") unless File.directory?(destination) destination = destination[0..-2] if destination.end_with?('/') @tmp_dir = false else destination = Dir.mktmpdir('obs-binary-download') @tmp_dir = true end @local_file_path = "#{destination}/#{@name}" @local_path = destination response = @connection.send_request(:get, "/build/#{CGI.escape(@package.project.name)}/#{CGI.escape(@repository.to_s)}/" \ "#{CGI.escape(@architecture)}/#{CGI.escape(@package.name)}/#{CGI.escape(@name)}") File.write(@local_file_path, response.body) @local_file_path end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/models/binary.rb', line 18 def to_s @name end |