Sha256: 8e5ba5ae1fe75106a70e75a969df0bc1da0576494c2f24bc5e1693c978430fd9

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

module Contracts
  module Core
    def self.included(base)
      common(base)
    end

    def self.extended(base)
      common(base)
    end

    def self.common(base)
      base.extend(MethodDecorators)

      base.instance_eval do
        def functype(funcname)
          contracts = Engine.fetch_from(self).decorated_methods_for(:class_methods, funcname)
          if contracts.nil?
            "No contract for #{self}.#{funcname}"
          else
            "#{funcname} :: #{contracts[0]}"
          end
        end
      end

      # NOTE: Workaround for `defined?(super)` bug in ruby 1.9.2
      # source: http://stackoverflow.com/a/11181685
      # bug: https://bugs.ruby-lang.org/issues/6644
      base.class_eval <<-RUBY
        # TODO: deprecate
        # Required when contracts are included in global scope
        def Contract(*args)
          if defined?(super)
            super
          else
            self.class.Contract(*args)
          end
        end
      RUBY

      base.class_eval do
        def functype(funcname)
          contracts = Engine.fetch_from(self.class).decorated_methods_for(:instance_methods, funcname)
          if contracts.nil?
            "No contract for #{self.class}.#{funcname}"
          else
            "#{funcname} :: #{contracts[0]}"
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 5 rubygems

Version Path
entitlements-app-1.1.0 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-1.0.0 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-0.3.4 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-0.3.1 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-0.3.0 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-0.2.1 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-0.2.1 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-0.2.0 lib/contracts-ruby2/lib/contracts/core.rb
entitlements-app-0.2.0 lib/contracts-ruby2/lib/contracts/core.rb
contracts-0.16.1 lib/contracts/core.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/contracts-0.16.0/lib/contracts/core.rb
contracts-0.16.0 lib/contracts/core.rb
contracts-0.15.0 lib/contracts/core.rb
contracts-lite-0.14.0 lib/contracts/core.rb
contracts-0.14.0 lib/contracts/core.rb