Sha256: ca20492a8e6792e8f48091e7496750ae223dfa0f9a33a662bcc501fdf7ec6e40

Contents?: true

Size: 1.97 KB

Versions: 77

Compression:

Stored size: 1.97 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
  module Model
    class SchemaBuilder
      attr_accessor :data

      class << self
        def create_from_data(blueprint)
          sc = SchemaBuilder.new
          sc.data = blueprint.to_hash
          sc
        end

        def create(id, options = {}, &block)
          pb = SchemaBuilder.new(id, options)
          block.call(pb)
          pb
        end
      end

      def initialize(id = nil, options = {})
        @data = {
          id: id,
          type: :dataset,
          columns: []
        }.merge(options)
      end

      def name
        data[:name]
      end

      def columns
        data[:columns]
      end

      def add_column(column_def)
        columns.push(column_def)
        self
      end

      def add_anchor(id, options = {})
        add_column({ type: :anchor, id: id }.merge(options))
        self
      end

      def add_attribute(id, options = {})
        add_column({ type: :attribute, id: id }.merge(options))
        self
      end

      def add_fact(id, options = {})
        data = { type: :fact, id: id }.merge(options)
        add_column(data)
        self
      end

      def add_label(id, options = {})
        add_column({ type: :label, id: id }.merge(options))
        self
      end

      def add_date(dataset_id, options = {})
        add_column({ type: :date, dataset: dataset_id, format: GoodData::Model::DEFAULT_DATE_FORMAT }.merge(options))
      end

      def add_reference(dataset, options = {})
        add_column({ type: :reference, dataset: dataset }.merge(options))
      end

      def to_json
        JSON.pretty_generate(to_hash)
      end

      def to_hash
        data
      end

      def to_blueprint
        GoodData::Model::ProjectBlueprint.new(datasets: [to_hash])
      end
    end
  end
end

Version data entries

77 entries across 77 versions & 1 rubygems

Version Path
gooddata-2.1.0-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-2.1.0 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-2.0.1-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-2.0.1 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-2.0.0-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-2.0.0 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.6-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.6 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.5-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.5 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.4-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.4 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.3-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.3 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.2-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.2 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.1-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.1 lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.0-java lib/gooddata/models/blueprint/schema_builder.rb
gooddata-1.3.0 lib/gooddata/models/blueprint/schema_builder.rb