Class: Linecook::Image
- Inherits:
-
Object
- Object
- Linecook::Image
- Includes:
- Crypto, Downloader
- Defined in:
- lib/linecook-gem/image.rb
Constant Summary collapse
- IMAGE_PATH =
File.join(Config::LINECOOK_HOME, 'images').freeze
Constants included from Downloader
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #clean(retention) ⇒ Object
- #fetch ⇒ Object
-
#initialize(name, group, tag) ⇒ Image
constructor
A new instance of Image.
- #latest ⇒ Object
- #list ⇒ Object
- #upload ⇒ Object
- #url ⇒ Object
Methods included from Crypto
Methods included from Downloader
Constructor Details
#initialize(name, group, tag) ⇒ Image
Returns a new instance of Image.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/linecook-gem/image.rb', line 19 def initialize(name, group, tag) @name = name @group = group ? "#{name}-#{group.gsub(/-|\//,'_')}" : name @tag = tag @id = if @tag == 'latest' id = File.basename(latest).split('.')[0] @tag = id.split('-').last id elsif tag "#{@group}-#{@tag}" else @group end @path = image_path end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
16 17 18 |
# File 'lib/linecook-gem/image.rb', line 16 def group @group end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/linecook-gem/image.rb', line 16 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/linecook-gem/image.rb', line 16 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/linecook-gem/image.rb', line 16 def path @path end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
16 17 18 |
# File 'lib/linecook-gem/image.rb', line 16 def tag @tag end |
Instance Method Details
#clean(retention) ⇒ Object
67 68 69 |
# File 'lib/linecook-gem/image.rb', line 67 def clean(retention) provider.clean(retention, @group) end |
#fetch ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/linecook-gem/image.rb', line 35 def fetch return if File.exists?(@path) Dir.mktmpdir("#{@id}-download") do |tmpdir| tmppath = File.join(tmpdir, File.basename(@path)) download(url, tmppath) FileUtils.mkdir_p(File.dirname(@path)) decrypt(tmppath, dest: @path) FileUtils.rm_f(tmppath) end end |
#latest ⇒ Object
63 64 65 |
# File 'lib/linecook-gem/image.rb', line 63 def latest provider.latest(@group) end |
#list ⇒ Object
59 60 61 |
# File 'lib/linecook-gem/image.rb', line 59 def list provider.list(group: @group) end |
#upload ⇒ Object
48 49 50 51 52 53 |
# File 'lib/linecook-gem/image.rb', line 48 def upload puts "Encrypting and uploading image #{@path}" encrypted = encrypt(@path) provider.upload(encrypted, group: @group) FileUtils.rm_f(encrypted) end |
#url ⇒ Object
55 56 57 |
# File 'lib/linecook-gem/image.rb', line 55 def url provider.url(@id, group: @group) end |