Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with hash complies #9

Merged
merged 5 commits into from
May 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/leap/committee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def report(characteristics, considerations, options = {})
Leap.log.committee "Convening committee", name
quorums.each do |quorum|
Leap.log.quorum "Assessing quorum", quorum.name
next unless quorum.satisfied_by? characteristics and quorum.complies_with? Array.wrap(options[:comply])
next unless quorum.satisfied_by? characteristics and quorum.complies_with? options[:comply]
Leap.log.quorum "Acknowledging quorum", quorum.name
if conclusion = quorum.acknowledge(characteristics.slice(*quorum.characteristics), considerations.dup)
Leap.log.quorum "Success", quorum.name
Expand Down
26 changes: 24 additions & 2 deletions lib/leap/quorum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,32 @@ def satisfied_by?(characteristics)
end

# Does the quorum comply with the given set of protocols?
# @param [Array] guideines The list of protocols we're for which we're checking compliance.
# @param [Array, Hash, Object] guidelines The list of protocols for which we're checking compliance.
# @return [TrueClass, NilClass]
def complies_with?(guidelines)
(guidelines - compliance).empty?
case guidelines
when Hash
inversion = guidelines.inject({}) do |memo, pair|
protocol, committees = pair
Array.wrap(committees).each do |committee|
if memo[committee]
memo[committee] << protocol
else
memo[committee] = [protocol]
end
end
memo
end
inversion.values.any? do |committee_guidelines|
(committee_guidelines - compliance).empty?
end
when Array
(guidelines - compliance).empty?
when NilClass
true
else
compliance.include? guidelines
end
end

# Perform the quorum's methodology using the given characteristics.
Expand Down
1 change: 1 addition & 0 deletions lib/leap/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def decide(goal, options = {}, &blk)
end
end
Leap.log.decision "Success", goal
@deliberations[goal]
else
Leap.log.decision "Success", goal
@deliberations[goal]
Expand Down
4 changes: 4 additions & 0 deletions test/test_leap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,9 @@ class Owl
end
assert_match(/No solution was found for "benefit"/, exception.message)
end

should 'return compliant values when compliance is requested for specific committees' do
assert_equal 100, @bad_idea.value(:comply => { :common_sense => :cost })[:cost]
end
end
end