Sha256: c63920a1bee972e9d34df36948f853f17689bac0ea484461657fda20b064a6c7

Contents?: true

Size: 1.38 KB

Versions: 14

Compression:

Stored size: 1.38 KB

Contents

module VagrantCloud
  class Organization < Data::Mutable
    attr_reader :account

    attr_required :username
    attr_optional :boxes, :avatar_url, :profile_html, :profile_markdown

    attr_mutable :boxes

    def initialize(account:, **opts)
      @account = account
      opts[:boxes] ||= []
      super(**opts)
      bxs = boxes.map do |b|
        if !b.is_a?(Box)
          b = Box.load(organization: self, **b)
        end
        b
      end
      clean(data: {boxes: bxs})
    end

    # Add a new box to the organization
    #
    # @param [String] name Name of the box
    # @return [Box]
    def add_box(name)
      if boxes.any? { |b| b.name == name }
        raise Error::BoxError::BoxExistsError,
          "Box with name #{name} already exists"
      end
      b = Box.new(organization: self, name: name)
      clean(data: {boxes: boxes + [b]})
      b
    end

    # Check if this instance is dirty
    #
    # @param [Boolean] deep Check nested instances
    # @return [Boolean] instance is dirty
    def dirty?(key=nil, deep: false)
      if key
        super(key)
      else
        d = super()
        if deep && !d
          d = boxes.any? { |b| b.dirty?(deep: true) }
        end
        d
      end
    end

    # Save the organization
    #
    # @return [self]
    # @note This only saves boxes within organization
    def save
      boxes.map(&:save)
      self
    end
  end
end

Version data entries

14 entries across 13 versions & 2 rubygems

Version Path
vagrant_cloud-3.1.2 lib/vagrant_cloud/organization.rb
vagrant_cloud-3.1.1 lib/vagrant_cloud/organization.rb
vagrant_cloud-3.1.0 lib/vagrant_cloud/organization.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/vagrant_cloud-3.0.5/lib/vagrant_cloud/organization.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/vagrant_cloud-3.0.5/lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.5 lib/vagrant_cloud/organization.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/vagrant_cloud-3.0.2/lib/vagrant_cloud/organization.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/vagrant_cloud-3.0.4/lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.4 lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.3 lib/vagrant_cloud/organization.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/vagrant_cloud-3.0.2/lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.2 lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.1 lib/vagrant_cloud/organization.rb
vagrant_cloud-3.0.0 lib/vagrant_cloud/organization.rb