Sha256: 7ccd31a30dad2f894e56bbb7e14d7fa5917c1732d7dcbc717e0b7da56686eb28

Contents?: true

Size: 1.68 KB

Versions: 23

Compression:

Stored size: 1.68 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2015 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 BlueprintField
      attr_reader :dataset_blueprint, :data

      def id
        @data[:id]
      end

      def initialize(data, dataset)
        @data = GoodData::Helpers.symbolize_keys(data)
        @data[:type] = @data[:type].to_sym
        @dataset_blueprint = dataset
      end

      # Returns the md object in associated project or throws error if not present
      #
      # @return [GoodData::MdObject] md object that is represented in the blueprint
      def in_project(project)
        GoodData::MdObject[id, project: project, client: project.client]
      end

      def method_missing(method_sym, *arguments, &block)
        if @data.key?(method_sym)
          @data[method_sym]
        else
          super
        end
      end

      def respond_to?(method_sym, *arguments, &block)
        if @data.key?(method_sym)
          true
        else
          super
        end
      end

      def title
        @data[:title] || GoodData::Helpers.titleize(@data[:id])
      end

      # Validates the fields in the field
      #
      # @return [Array] returns list of the errors represented by hash structures
      def validate
        []
      end

      def ==(other)
        return false unless other.respond_to?(:data)
        @data == other.data
      end

      private

      def validate_presence_of(*fields)
        fields.reduce([]) do |a, e|
          data.key?(e) && !data[e].blank? ? a : a + [e]
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
gooddata-edge-0.6.27.edge lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.43 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.42 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.41 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.40 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.39 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.38 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.37 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.36 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.35 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.34 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.33 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.32 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.31 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.30 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.29 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.28 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.27 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.26 lib/gooddata/models/blueprint/blueprint_field.rb
gooddata-0.6.25 lib/gooddata/models/blueprint/blueprint_field.rb