Sha256: e50749e2d9273cc37b1985819f529e164741a82ced1bf1b438611a5d000ca46c

Contents?: true

Size: 741 Bytes

Versions: 3

Compression:

Stored size: 741 Bytes

Contents

require 'rom/mapper_builder'

module ROM

  class CommandDSL
    attr_reader :commands

    class CommandDefinition
      attr_reader :options

      def initialize(options, &block)
        @options = options
        instance_exec(&block) if block
      end

      def to_h
        options
      end

      def type
        options[:type]
      end

      def method_missing(name, *args, &block)
        if args.size == 1
          options[name] = args.first
        else
          super
        end
      end
    end

    def initialize
      @commands = {}
    end

    def call
      commands
    end

    def define(name, options = {}, &block)
      commands[name] = CommandDefinition.new(options, &block)
      self
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-0.4.2 lib/rom/boot/command_dsl.rb
rom-0.4.1 lib/rom/boot/command_dsl.rb
rom-0.4.0 lib/rom/boot/command_dsl.rb