Class: RSpec::Contracts::Fulfillment

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/contracts/fulfillment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interfaces, implementors) ⇒ Fulfillment

Returns a new instance of Fulfillment.



8
9
10
11
12
13
# File 'lib/rspec/contracts/fulfillment.rb', line 8

def initialize(interfaces, implementors)
  @implementors = implementors
  @interface_fulfillments = interfaces.map do |interface|
    InterfaceFulfillment.new interface, implementors_for(interface)
  end
end

Instance Attribute Details

#interface_fulfillmentsObject (readonly)

Returns the value of attribute interface_fulfillments.



6
7
8
# File 'lib/rspec/contracts/fulfillment.rb', line 6

def interface_fulfillments
  @interface_fulfillments
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rspec/contracts/fulfillment.rb', line 15

def complete?
  incomplete_interfaces.empty?
end

#implementors_for(interface) ⇒ Object



27
28
29
# File 'lib/rspec/contracts/fulfillment.rb', line 27

def implementors_for(interface)
  @implementors.select{ |i| i.interface_names.include? interface.name }
end

#incomplete_interfacesObject



19
20
21
# File 'lib/rspec/contracts/fulfillment.rb', line 19

def incomplete_interfaces
  interface_fulfillments.reject(&:complete?)
end

#messages_countObject



23
24
25
# File 'lib/rspec/contracts/fulfillment.rb', line 23

def messages_count
  interface_fulfillments.map(&:messages_count).inject(&:+) || 0
end