Sha256: 51df13f30eb99c18a60173a412641522c9de821300f59823c8da941f207cc8af

Contents?: true

Size: 1.47 KB

Versions: 26

Compression:

Stored size: 1.47 KB

Contents

module Foobara
  module Organization
    class OrganizationAlreadyExistsError < StandardError; end
    class NoSuchOrganization < StandardError; end

    class << self
      # TODO: move this to organization.rb
      def to_organization(object)
        case object
        when nil
          GlobalOrganization
        when ::String, ::Symbol
          organization = Namespace.global.foobara_lookup_organization(object)

          unless organization
            # :nocov:
            raise NoSuchOrganization, "Couldn't determine organization for #{object}"
            # :nocov:
          end

          organization
        when Foobara::Scoped
          if object.is_a?(Module) && object.foobara_organization?
            object
          else
            parent = object.scoped_namespace

            if parent
              to_organization(parent)
            else
              GlobalOrganization
            end
          end
        else
          # :nocov:
          raise NoSuchOrganization, "Couldn't determine organization for #{object}"
          # :nocov:
        end
      end

      def create(full_organization_name)
        if Organization.to_organization(full_organization_name)
          # :nocov:
          raise OrganizationAlreadyExistsError, "Organization #{full_organization_name} already exists"
          # :nocov:
        end
      rescue Organization::NoSuchOrganization
        Util.make_module_p(full_organization_name) { foobara_organization! }
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/domain/src/organization.rb
foobara-0.0.25 projects/domain/src/organization.rb
foobara-0.0.24 projects/domain/src/organization.rb
foobara-0.0.23 projects/domain/src/organization.rb
foobara-0.0.22 projects/domain/src/organization.rb
foobara-0.0.21 projects/domain/src/organization.rb
foobara-0.0.20 projects/domain/src/organization.rb
foobara-0.0.19 projects/domain/src/organization.rb
foobara-0.0.18 projects/domain/src/organization.rb
foobara-0.0.17 projects/domain/src/organization.rb
foobara-0.0.16 projects/domain/src/organization.rb
foobara-0.0.15 projects/domain/src/organization.rb
foobara-0.0.14 projects/domain/src/organization.rb
foobara-0.0.13 projects/domain/src/organization.rb
foobara-0.0.12 projects/domain/src/organization.rb
foobara-0.0.11 projects/domain/src/organization.rb
foobara-0.0.10 projects/domain/src/organization.rb
foobara-0.0.9 projects/domain/src/organization.rb
foobara-0.0.8 projects/domain/src/organization.rb
foobara-0.0.7 projects/domain/src/organization.rb