class GoodData::Variable

Public Class Methods

all(options = { :client => GoodData.connection, :project => GoodData.project }) click to toggle source

Method intended to get all objects of that type in a specified project

@param options [Hash] the options hash @option options [Boolean] :full if passed true the subclass can decide to pull in full objects. This is desirable from the usability POV but unfortunately has negative impact on performance so it is not the default @return [Array<GoodData::MdObject> | Array<Hash>] Return the appropriate metadata objects or their representation

# File lib/gooddata/models/metadata/variable.rb, line 22
def all(options = { :client => GoodData.connection, :project => GoodData.project })
  query('prompt', Variable, options)
end
create(data, options = { :client => GoodData.connection, :project => GoodData.project }) click to toggle source
# File lib/gooddata/models/metadata/variable.rb, line 26
def create(data, options = { :client => GoodData.connection, :project => GoodData.project })
  title = data[:title]
  project = options[:project]
  c = client(options)
  attribute = project.attributes(data[:attribute])

  payload = {
    'prompt' => {
      'content' => {
        'attribute' => attribute.uri,
        'type' => 'filter'
      },
      'meta' => {
        'tags' => '',
        'deprecated' => '0',
        'summary' => '',
        'title' => title,
        'category' => 'prompt'
      }
    }
  }
  c.create(self, payload, project: project)
end

Public Instance Methods

delete() click to toggle source

Deletes all the values and eventually the variable itself

Calls superclass method GoodData::MdObject#delete
# File lib/gooddata/models/metadata/variable.rb, line 91
def delete
  values.pmap(&:delete)
  super
end
project_values() click to toggle source

Retrieves variable values and returns only those related to project

@return [Array<GoodData::VariableUserFilter>] Values of variable related to project

# File lib/gooddata/models/metadata/variable.rb, line 86
def project_values
  values.select { |x| x.level == :project }
end
replace(mapping) click to toggle source

Method used for replacing values in their state according to mapping. Can be used to replace any values but it is typically used to replace the URIs. Returns a new object of the same type.

@param [Array<Array>]Mapping specifying what should be exchanged for what. As mapping should be used output of GoodData::Helpers.prepare_mapping. @return [GoodData::Variable]

# File lib/gooddata/models/metadata/variable.rb, line 79
def replace(mapping)
  GoodData::MdObject.replace_quoted(self, mapping)
end
user_values() click to toggle source

Retrieves variable values and returns only those related to user

@return [Array<GoodData::VariableUserFilter>] Values of variable related to user

# File lib/gooddata/models/metadata/variable.rb, line 69
def user_values
  values.select { |x| x.level == :user }
end
values() click to toggle source

Retrieves variable values

@return [Array<GoodData::VariableUserFilter>] Values of variable

# File lib/gooddata/models/metadata/variable.rb, line 54
def values
  payload = {
    variablesSearch: {
      variables: [
        uri
      ],
      context: []
    }
  }
  client.post("/gdc/md/#{project.pid}/variables/search", payload)['variables'].map { |f| client.create(GoodData::VariableUserFilter, f, project: project) }
end