Sha256: 2f2f2bfecff5186f81e2097a32cea04ae38fc8cb77ef533a696fc22bbb208826

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

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
      alias_method('configure', 'evaluate')
    end
  end

  def Dao.api(&block)
    if block
      Class.new(Api).tap{|api| api.evaluate(&block)}
    else
      Class.new(Api)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dao-5.6.1 lib/dao/api/dsl.rb
dao-5.5.2 lib/dao/api/dsl.rb
dao-5.5.1 lib/dao/api/dsl.rb
dao-5.5.0 lib/dao/api/dsl.rb
dao-5.4.0 lib/dao/api/dsl.rb
dao-5.3.3 lib/dao/api/dsl.rb
dao-5.3.2 lib/dao/api/dsl.rb
dao-5.3.0 lib/dao/api/dsl.rb
dao-5.2.1 lib/dao/api/dsl.rb
dao-5.1.2 lib/dao/api/dsl.rb