Sha256: 28d5abf6ec6a0b1df9e26eb0939ce8554dbd754c7ca9f102b091cca0b865244e

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

require 'rom/mapper_builder'

module ROM
  class Setup
    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

        private

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

      def initialize(&block)
        @commands = {}
        instance_exec(&block)
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.5.0 lib/rom/setup/command_dsl.rb