Sha256: e375740b7ddb9b22c6b3b766cec24c71876d2613b5f7806c55b540ec836db099

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

module VagrantPlugins
  module Cloudstack
    module Model
      class CloudstackResource
        attr_accessor :id, :name, :details
        attr_reader   :kind

        def initialize(id, name, kind)
          raise 'Resource must have a kind' if kind.nil? || kind.empty?
          @id             = id
          @name           = name
          @kind           = kind
        end

        def is_undefined?
          is_id_undefined? and is_name_undefined?
        end

        def is_id_undefined?
          id.nil? || id.empty?
        end

        def is_name_undefined?
          name.nil? || name.empty?
        end

        def to_s
          "#{kind} - #{id || '<unknown id>'}:#{name || '<unknown name>'}"
        end

        def self.create_list(ids, names, kind)
          return create_id_list(ids, kind)     unless ids.empty?
          return create_name_list(names, kind) unless names.empty?
          []
        end

        def self.create_id_list(ids, kind)
          ids.each_with_object([]) do |id, resources|
            resources << CloudstackResource.new(id, nil, kind)
          end
        end

        def self.create_name_list(names, kind)
          names.each_with_object([]) do |name, resources|
            resources << CloudstackResource.new(nil, name, kind)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-cloudstack-1.5.2 lib/vagrant-cloudstack/model/cloudstack_resource.rb
vagrant-cloudstack-1.5.1 lib/vagrant-cloudstack/model/cloudstack_resource.rb
vagrant-cloudstack-1.5.0 lib/vagrant-cloudstack/model/cloudstack_resource.rb
vagrant-cloudstack-1.4.0 lib/vagrant-cloudstack/model/cloudstack_resource.rb