lib/gooddata/models/blueprint/project_blueprint.rb in gooddata-0.6.51 vs lib/gooddata/models/blueprint/project_blueprint.rb in gooddata-0.6.52
- old
+ new
@@ -49,13 +49,16 @@
# Removes dataset from blueprint. Dataset can be given as either a name
# or a DatasetBlueprint or a Hash representation.
#
# @param project [Hash | GoodData::Model::ProjectBlueprint] Project blueprint
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Hash] new project with removed dataset
- def self.remove_dataset(project, dataset_id)
- dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id) : dataset_name
+ def self.remove_dataset(project, dataset_id, options = {})
+ dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id, options) : dataset_name
index = project[:datasets].index(dataset)
dupped_project = GoodData::Helpers.deep_dup(project)
dupped_project[:datasets].delete_at(index)
dupped_project
end
@@ -64,24 +67,29 @@
# or a DatasetBlueprint or a Hash representation. This version mutates
# the dataset in place
#
# @param project [Hash | GoodData::Model::ProjectBlueprint] Project blueprint
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Hash] project with removed dataset
- def self.remove_dataset!(project, dataset_id)
+ def self.remove_dataset!(project, dataset_id, options = {})
project = project.to_hash
- dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id) : dataset_id
+ dataset = dataset_id.is_a?(String) ? find_dataset(project, dataset_id, options) : dataset_id
index = project[:datasets].index(dataset)
project[:datasets].delete_at(index)
project
end
# Returns datasets of blueprint. Those can be optionally including
# date dimensions
#
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
# @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Array<Hash>]
def self.datasets(project_blueprint, options = {})
project_blueprint = project_blueprint.to_hash
include_date_dimensions = options[:include_date_dimensions] || options[:dd]
ds = (project_blueprint.to_hash[:datasets] || [])
@@ -108,10 +116,13 @@
# Returns true if a dataset contains a particular dataset false otherwise
#
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Boolean]
def self.dataset?(project, name, options = {})
find_dataset(project, name, options)
true
rescue
@@ -121,10 +132,12 @@
# Returns dataset specified. It can check even for a date dimension
#
# @param project [GoodData::Model::ProjectBlueprint | Hash] Project blueprint
# @param obj [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
# @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [GoodData::Model::DatasetBlueprint]
def self.find_dataset(project_blueprint, obj, options = {})
return obj.to_hash if DatasetBlueprint.dataset_blueprint?(obj)
all_datasets = datasets(project_blueprint, options)
name = obj.respond_to?(:to_hash) ? obj.to_hash[:id] : obj
@@ -187,10 +200,12 @@
# Returns datasets of blueprint. Those can be optionally including
# date dimensions
#
# @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Array<GoodData::Model::DatasetBlueprint>]
def datasets(id = :all, options = {})
id = id.respond_to?(:id) ? id.id : id
dss = ProjectBlueprint.datasets(self, options).map do |d|
case d[:type]
@@ -333,10 +348,13 @@
end
# Returns true if a dataset contains a particular dataset false otherwise
#
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Boolean]
def dataset?(name, options = {})
ProjectBlueprint.dataset?(to_hash, name, options)
end
@@ -375,10 +393,12 @@
# Returns dataset specified. It can check even for a date dimension
#
# @param name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset
# @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [GoodData::Model::DatasetBlueprint]
def find_dataset(name, options = {})
ds = datasets(name, options)
fail "Dataset \"#{name}\" could not be found" unless ds
ds
@@ -402,11 +422,14 @@
datasets.select { |d| d.referenced_by.empty? }
end
# Constructor
#
- # @param init_data [ProjectBlueprint | Hash] Blueprint or a blueprint definition. If passed a hash it is used as data for new instance. If there is a ProjectBlueprint passed it is duplicated and a new instance is created.
+ # @param init_data [ProjectBlueprint | Hash] Blueprint or a blueprint
+ # definition. If passed a hash it is used as data for new instance.
+ # If there is a ProjectBlueprint passed it is duplicated and a new
+ # instance is created.
# @return [ProjectBlueprint] A new project blueprint instance
def initialize(init_data)
some_data = if init_data.respond_to?(:project_blueprint?) && init_data.project_blueprint?
init_data.to_hash
elsif init_data.respond_to?(:to_blueprint)
@@ -422,10 +445,11 @@
end
end
(@data[:date_dimensions] || []).each do |d|
d[:type] = d[:type].to_sym
end
+ @data[:include_ca] = true if @data[:include_ca].nil?
end
def id
data[:id]
end
@@ -508,23 +532,29 @@
# Removes dataset from blueprint. Dataset can be given as either a name
# or a DatasetBlueprint or a Hash representation.
#
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Hash] project with removed dataset
- def remove_dataset(dataset_name)
- ProjectBlueprint.remove_dataset(to_hash, dataset_name)
+ def remove_dataset(dataset_name, options = {})
+ ProjectBlueprint.remove_dataset(to_hash, dataset_name, options)
self
end
# Removes dataset from blueprint. Dataset can be given as either a name
# or a DatasetBlueprint or a Hash representation.
#
# @param dataset_name [GoodData::Model::DatasetBlueprint | String | Hash] Dataset to be removed
+ # @param options [Hash] options
+ # @option options [Boolean] :include_date_dimensions Specifies whether to include date dimensions
+ # @option options [Boolean] :dd Specifies whether to include date dimensions
# @return [Hash] project with removed dataset
- def remove_dataset!(dataset_id)
- ProjectBlueprint.remove_dataset!(to_hash, dataset_id)
+ def remove_dataset!(dataset_id, options = {})
+ ProjectBlueprint.remove_dataset!(to_hash, dataset_id, options)
self
end
# Removes all the labels from the anchor. This is a typical operation that people want to
# perform on fact tables
@@ -638,11 +668,11 @@
temp_blueprint.add_dataset!(dataset.dup)
end
end
a_blueprint.date_dimensions.each do |dd|
if temp_blueprint.dataset?(dd.id, dd: true)
- local_dim = temp_blueprint.find_dataset(dd.id, dd: true)
- fail "Unable to merge date dimensions #{dd.id} with defintion #{dd.data} with #{local_dim.data}" unless local_dim.data == dd.data
+ local_dim = temp_blueprint.data[:date_dimensions].find { |d| d[:id] == dd.id }
+ local_dim[:urn] = dd.urn
else
temp_blueprint.add_date_dimension!(dd.dup)
end
end
temp_blueprint