Sha256: 2479db75ad8dbfe751a47b01696716ecabbe5f3a32109833b77fc7416da5b867

Contents?: true

Size: 1.99 KB

Versions: 77

Compression:

Stored size: 1.99 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

module GoodData
  @project = nil

  class << self
    # Sets the active project
    #
    # @param project A project identifier
    #
    # ### Examples
    #
    # The following calls are equivalent
    #
    #     # Assign project ID
    #     GoodData.project = 'afawtv356b6usdfsdf34vt'
    #
    #     # Use project ID
    #     GoodData.use 'afawtv356b6usdfsdf34vt'
    #
    #     # Use project URL
    #     GoodData.use '/gdc/projects/afawtv356b6usdfsdf34vt'
    #
    #     # Select project using indexer on GoodData::Project class
    #     GoodData.project = Project['afawtv356b6usdfsdf34vt']
    # Assigns global/default GoodData project
    def project=(project, opts = { :client => GoodData.connection })
      if project.is_a? Project
        @project = project
      elsif project.nil?
        @project = nil
      else
        @project = Project[project, opts]
      end
      @project
    end

    alias_method :use, :project=

    attr_reader :project

    # Returns the active project
    #
    # def project
    #   threaded[:project]
    # end

    # Perform block in context of another project than currently set
    #
    # @param project Project to use
    # @param bl Block to be performed
    def with_project(project, opts = { :client => GoodData.connection }, &bl)
      fail 'You have to specify a project when using with_project' if project.nil? || (project.is_a?(String) && project.empty?)
      fail 'You have to specify block' unless bl
      old_project = GoodData.project

      begin
        GoodData.use(project, opts)
        res = bl.call(GoodData.project)
      rescue RestClient::ResourceNotFound
        GoodData.project = old_project
        raise(GoodData::ProjectNotFound, 'Project was not found')
      end

      GoodData.project = old_project

      res
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
gooddata-2.1.0-java lib/gooddata/core/project.rb
gooddata-2.1.0 lib/gooddata/core/project.rb
gooddata-2.0.1-java lib/gooddata/core/project.rb
gooddata-2.0.1 lib/gooddata/core/project.rb
gooddata-2.0.0-java lib/gooddata/core/project.rb
gooddata-2.0.0 lib/gooddata/core/project.rb
gooddata-1.3.6-java lib/gooddata/core/project.rb
gooddata-1.3.6 lib/gooddata/core/project.rb
gooddata-1.3.5-java lib/gooddata/core/project.rb
gooddata-1.3.5 lib/gooddata/core/project.rb
gooddata-1.3.4-java lib/gooddata/core/project.rb
gooddata-1.3.4 lib/gooddata/core/project.rb
gooddata-1.3.3-java lib/gooddata/core/project.rb
gooddata-1.3.3 lib/gooddata/core/project.rb
gooddata-1.3.2-java lib/gooddata/core/project.rb
gooddata-1.3.2 lib/gooddata/core/project.rb
gooddata-1.3.1-java lib/gooddata/core/project.rb
gooddata-1.3.1 lib/gooddata/core/project.rb
gooddata-1.3.0-java lib/gooddata/core/project.rb
gooddata-1.3.0 lib/gooddata/core/project.rb