Sha256: 4f1885546ab27acc730783cdb8a34fd24a1d272f3ffcebc3aabadf05ac7ecb6b

Contents?: true

Size: 1012 Bytes

Versions: 5

Compression:

Stored size: 1012 Bytes

Contents

# -*- encoding : utf-8 -*-
module Dao
  class Api
    class DSL < BlankSlate
      attr_accessor :api

      def initialize(api)
        @api = api
        #@evaluate = Object.instance_method(:instance_eval).bind(self)
      end

      def evaluate(&block)
        #@evaluate.call(&block)
        @api.module_eval(&block)
      ensure
        #no_docs_left_on_stack!
      end

      def no_docs_left_on_stack!
        raise "no interface for #{ docs.inspect }" unless docs.empty?
      end

      %w( interface call doc docs description desc ).each do |method|
        module_eval <<-__, __FILE__, __LINE__ - 1

          def #{ method }(*args, &block)
            api.#{ method }(*args, &block)
          end

        __
      end
    end

    class << Api
      def evaluate(&block)
        @dsl ||= DSL.new(api=self)
        @dsl.evaluate(&block)
      end
    end
  end

  def Dao.api(&block)
    if block
      api = Class.new(Api)
      api.evaluate(&block)
      api
    else
      Api
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dao-5.1.1 lib/dao/api/dsl.rb
dao-5.0.0 lib/dao/api/dsl.rb
dao-4.6.4 lib/dao/api/dsl.rb
dao-4.4.4 lib/dao/api/dsl.rb
dao-4.4.2 lib/dao/api/dsl.rb