Sha256: 05c4463a68c5b6846593a4013f5bc7c30b8d7eea8083dff4d435ee0b5be39303

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

module VagrantCloud

  class Version

    attr_accessor :box
    attr_accessor :number
    attr_accessor :data

    def initialize(box, number, data = nil)
      @box = box
      @number = number
      @data = data
    end

    def version
      data['version']
    end

    def description
      data['description_markdown']
    end

    def providers
      data['providers'].map { |data| Provider.new(self, data['name'], data) }
    end

    def data
      @data ||= account.request('get', "/box/#{account.username}/#{box.name}/version/#{number}")
    end

    def update(description)
      version = {:description => description}
      @data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}", {:version => version})
    end

    def delete
      account.request('delete', "/box/#{account.username}/#{box.name}/version/#{number}")
    end

    def release
      @data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}/release")
    end

    def revoke
      @data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}/revoke")
    end

    def get_provider(name, data = nil)
      Provider.new(self, name, data)
    end

    def create_provider(name, url)
      params = {:name => name, :url => url}
      data = account.request('post', "/box/#{account.username}/#{box.name}/version/#{self.number}/providers", {:provider => params})
      get_provider(name, data)
    end

    def ensure_provider(name, url)
      provider = providers.select{ |provider| provider.name == name }.first
      unless provider
        provider = create_provider(name, url)
      end
      if url != provider.url
        provider.update(url)
      end
      provider
    end

    private

    def account
      box.account
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant_cloud-0.1.0 lib/vagrant_cloud/version.rb