Sha256: fb96fc85fbcd470fa30379c269abbd0db5fabab5ecf0c20fbb8be5c54d9b0e0e

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

# encoding: UTF-8

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
      end

      def initialize(name = nil)
        @data = {
          :name => name,
          :columns => []
        }
      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(name, options = {})
        add_column({ :type => :anchor, :name => name }.merge(options))
        self
      end

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

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

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

      def add_date(name, options = {})
        add_column({ :type => :date, :name => name }.merge(options))
      end

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

      def to_json
        JSON.pretty_generate(to_hash)
      end

      def to_hash
        data
      end

      def to_blueprint
        GoodData::Model::DatasetBlueprint.new(to_hash)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gooddata-0.6.18 lib/gooddata/models/schema_builder.rb
gooddata-0.6.17 lib/gooddata/models/schema_builder.rb
gooddata-0.6.16 lib/gooddata/models/schema_builder.rb
gooddata-0.6.15 lib/gooddata/models/schema_builder.rb
gooddata-0.6.14 lib/gooddata/models/schema_builder.rb
gooddata-0.6.13 lib/gooddata/models/schema_builder.rb
gooddata-0.6.12 lib/gooddata/models/schema_builder.rb
gooddata-0.6.11 lib/gooddata/models/schema_builder.rb
gooddata-0.6.10 lib/gooddata/models/schema_builder.rb
gooddata-0.6.9 lib/gooddata/models/schema_builder.rb
gooddata-0.6.8 lib/gooddata/models/schema_builder.rb
gooddata-0.6.7 lib/gooddata/models/schema_builder.rb
gooddata-0.6.6 lib/gooddata/models/schema_builder.rb
gooddata-0.6.5 lib/gooddata/models/schema_builder.rb