Sha256: 13901278537ef24824bffda39371660a30d3c2cf08e46c7cbd1513870fde179c

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module Cistern::Request
  include Cistern::HashSupport

  def self.cistern_request(cistern, klass, name)
    unless klass.name || klass.cistern_method
      fail ArgumentError, "can't turn anonymous class into a Cistern request"
    end

    cistern::Mock.module_eval <<-EOS, __FILE__, __LINE__
      def #{name}(*args)
        #{klass}.new(self)._mock(*args)
      end
    EOS

    cistern::Real.module_eval <<-EOS, __FILE__, __LINE__
      def #{name}(*args)
        #{klass}.new(self)._real(*args)
      end
    EOS
  end

  def self.service_request(*args)
    Cistern.deprecation(
      '#service_request is deprecated.  Please use #cistern_request',
      caller[0]
    )
    cistern_request(*args)
  end

  attr_reader :cistern

  def service
    Cistern.deprecation(
      '#service is deprecated.  Please use #cistern',
      caller[0]
    )
    @cistern
  end

  def initialize(cistern)
    @cistern = cistern
  end

  module ClassMethods
    # @deprecated Use {#cistern_method} instead
    def service_method(name = nil)
      Cistern.deprecation(
        '#service_method is deprecated.  Please use #cistern_method',
        caller[0]
      )
      @_cistern_method ||= name
    end

    def cistern_method(name = nil)
      @_cistern_method ||= name
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cistern-2.6.0 lib/cistern/request.rb
cistern-2.5.0 lib/cistern/request.rb
cistern-2.4.1 lib/cistern/request.rb
cistern-2.4.0 lib/cistern/request.rb