Sha256: 9960059aa06c1fcada5334c9ae2154957e28328d86127343982304ce8021aac5

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module BusinessCentral
  module Object
    class DefaultDimension < Base
      OBJECT = 'defaultDimensions'.freeze

      OBJECT_VALIDATION = {
        parent_id: {
          required: true
        },
        dimension_code: {
          maximum_length: 20
        },
        dimension_value_code: {
          maximum_length: 20
        }
      }.freeze

      OBJECT_METHODS = [
        :get,
        :post,
        :patch,
        :delete
      ].freeze

      OBJECT_PARENTS = [
        'items',
        'customers',
        'vendors',
        'employees'
      ].freeze

      def initialize(client, company_id:, parent:, parent_id:)
        raise InvalidArgumentException.new("parents allowed: #{OBJECT_PARENTS.join(', ')}") if !valid_parent?(parent)
        super(client, company_id: company_id)
        @parent_path << {
          path: parent.downcase,
          id: parent_id
        }
        @parent_id = parent_id
      end

      def create(params = {})
        params[:parent_id] = @parent_id
        super(params)
      end

      private

      def valid_parent?(parent)
        OBJECT_PARENTS.include?(parent.downcase)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
business-central-1.0.3 lib/business_central/object/default_dimension.rb