Sha256: 216a16d3c3fc1047cc46d9e63e510015bc42a73085ba39e47b984f3344f3efdb

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

require 'rom/support/constants'

require 'rom/configuration_dsl/relation'
require 'rom/configuration_dsl/mapper_dsl'
require 'rom/configuration_dsl/command_dsl'

module ROM
  # This extends Configuration class with the DSL methods
  #
  # @api public
  module ConfigurationDSL
    # Relation definition DSL
    #
    # @example
    #
    #   setup.relation(:users) do
    #     def names
    #       project(:name)
    #     end
    #   end
    #
    # @api public
    def relation(name, options = EMPTY_HASH, &block)
      klass_opts = { adapter: default_adapter }.merge(options)
      klass = Relation.build_class(name, klass_opts)
      klass.register_as(name)
      klass.class_eval(&block) if block
      register_relation(klass)
      klass
    end

    # Mapper definition DSL
    #
    # @example
    #
    #   setup.mappers do
    #     define(:users) do
    #       model name: 'User'
    #     end
    #
    #     define(:names, parent: :users) do
    #       exclude :id
    #     end
    #   end
    #
    # @api public
    def mappers(&block)
      register_mapper(*MapperDSL.new(self, mapper_classes, block).mapper_classes)
    end

    # Command definition DSL
    #
    # @example
    #
    #   setup.commands(:users) do
    #     define(:create) do
    #       input NewUserParams
    #       validator NewUserValidator
    #       result :one
    #     end
    #
    #     define(:update) do
    #       input UserParams
    #       validator UserValidator
    #       result :many
    #     end
    #
    #     define(:delete) do
    #       result :many
    #     end
    #   end
    #
    # @api public
    def commands(name, &block)
      register_command(*CommandDSL.new(name, default_adapter, &block).command_classes)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-2.0.2 lib/rom/configuration_dsl.rb
rom-2.0.1 lib/rom/configuration_dsl.rb
rom-2.0.0 lib/rom/configuration_dsl.rb
rom-1.0.0 lib/rom/configuration_dsl.rb
rom-1.0.0.rc1 lib/rom/configuration_dsl.rb
rom-1.0.0.beta2 lib/rom/configuration_dsl.rb
rom-1.0.0.beta1 lib/rom/configuration_dsl.rb