Module: Contracts::Core

Included in:
A, B, BareOptionalContractUsed, Entitlements, Entitlements::Auditor::Base, Entitlements::Backend::BaseController, Entitlements::Backend::BaseProvider, Entitlements::Backend::Dummy::Controller, Entitlements::Backend::LDAP::Controller, Entitlements::Backend::LDAP::Provider, Entitlements::Backend::MemberOf::Controller, Entitlements::Cli, Entitlements::Data::Groups::Cached, Entitlements::Data::Groups::Calculated, Entitlements::Data::Groups::Calculated::Base, Entitlements::Data::Groups::Calculated::Filters::Base, Entitlements::Data::Groups::Calculated::Filters::MemberOfGroup, Entitlements::Data::Groups::Calculated::Modifiers::Base, Entitlements::Data::Groups::Calculated::Modifiers::Expiration, Entitlements::Data::Groups::Calculated::Ruby, Entitlements::Data::Groups::Calculated::Rules::Base, Entitlements::Data::Groups::Calculated::Rules::Username, Entitlements::Data::Groups::Calculated::Text, Entitlements::Data::Groups::Calculated::YAML, Entitlements::Data::People, Entitlements::Data::People::Combined, Entitlements::Data::People::Dummy, Entitlements::Data::People::LDAP, Entitlements::Data::People::YAML, Entitlements::Extras, Entitlements::Extras::Base, Entitlements::Extras::LDAPGroup::Filters::MemberOfLDAPGroup, Entitlements::Extras::LDAPGroup::Rules::LDAPGroup, Entitlements::Extras::Orgchart::Logic, Entitlements::Extras::Orgchart::PersonMethods, Entitlements::Extras::Orgchart::Rules::DirectReport, Entitlements::Extras::Orgchart::Rules::Management, Entitlements::Models::Action, Entitlements::Models::Group, Entitlements::Models::Person, Entitlements::Plugins::Dummy, Entitlements::Plugins::GroupOfNames, Entitlements::Plugins::PosixGroup, Entitlements::Rule::Base, Entitlements::Service::LDAP, Entitlements::Util::Mirror, Entitlements::Util::Override, Entitlements::Util::Util, F, GenericExample, Mod, ModuleContractExample, ModuleExample, ModuleWithContracts::ClassMethods, MyBirthday, Parent, PatternMatchingExample, SingletonClassExample, SingletonInheritanceExample
Defined in:
lib/contracts-ruby2/lib/contracts/core.rb,
lib/contracts-ruby3/lib/contracts/core.rb

Class Method Summary collapse

Class Method Details

.common(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/contracts-ruby2/lib/contracts/core.rb', line 11

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

.extended(base) ⇒ Object



7
8
9
# File 'lib/contracts-ruby2/lib/contracts/core.rb', line 7

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

.included(base) ⇒ Object



3
4
5
# File 'lib/contracts-ruby2/lib/contracts/core.rb', line 3

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