Sha256: 1356778cf2b767cc62d567192a09e4fa4944a102ddb5823679218fde35e5966d

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

module Hcloud
  class Image
    Attributes = {
      id: nil,
      type: nil,
      status: nil,
      name: nil,
      description: nil,
      image_size: nil,
      disk_size: nil,
      created: :time,
      created_from: nil,
      bound_to: nil,
      os_flavor: nil,
      os_version: nil,
      rapid_deploy: nil,
    }

    include EntryLoader

    def to_snapshot
      update(type: "snapshot")
    end

    def update(description: nil, type: nil)
      query = {}
      method(:update).parameters.inject(query) do |r,x| 
        (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
      end
      Image.new(
        Oj.load(request("images/#{id.to_i}", j: query, method: :put).run.body)["image"],
        parent,
        client
      )
    end

    def destory
      request("images/#{id.to_i}", method: :delete).run
      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hcloud-0.1.0.pre.alpha4 lib/hcloud/image.rb
hcloud-0.1.0.pre.alpha3 lib/hcloud/image.rb