leap 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/leap.gemspec +2 -2
- data/lib/leap/committee.rb +2 -2
- data/lib/leap/decision.rb +3 -2
- data/lib/leap/report.rb +13 -4
- data/lib/leap/subject.rb +1 -1
- data/test/leap/test_report.rb +84 -5
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
data/leap.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{leap}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andy Rossmeissl", "Seamus Abshere"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-04}
|
13
13
|
s.description = %q{Leap to conclusions}
|
14
14
|
s.email = %q{andy@rossmeissl.net}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/leap/committee.rb
CHANGED
@@ -9,11 +9,11 @@ module Leap
|
|
9
9
|
@quorums = []
|
10
10
|
end
|
11
11
|
|
12
|
-
def report(characteristics, considerations, options = {})
|
12
|
+
def report(subject, characteristics, considerations, options = {})
|
13
13
|
quorums.grab do |quorum|
|
14
14
|
next unless quorum.satisfied_by? characteristics and quorum.complies_with? Array.wrap(options[:comply])
|
15
15
|
if conclusion = quorum.acknowledge(characteristics.slice(*quorum.characteristics), considerations.dup)
|
16
|
-
::Leap::Report.new self, quorum => conclusion
|
16
|
+
::Leap::Report.new subject, self, quorum => conclusion
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/leap/decision.rb
CHANGED
@@ -8,10 +8,11 @@ module Leap
|
|
8
8
|
@committees = []
|
9
9
|
end
|
10
10
|
|
11
|
-
def make(
|
11
|
+
def make(subject, *considerations)
|
12
|
+
characteristics = subject.send(subject.class.decisions[goal].signature_method)
|
12
13
|
options = considerations.extract_options!
|
13
14
|
committees.reject { |c| characteristics.keys.include? c.name }.reverse.inject(Deliberation.new(characteristics)) do |deliberation, committee|
|
14
|
-
if report = committee.report(deliberation.characteristics, considerations, options)
|
15
|
+
if report = committee.report(subject, deliberation.characteristics, considerations, options)
|
15
16
|
deliberation.reports.unshift report
|
16
17
|
deliberation.characteristics[committee.name] = report.conclusion
|
17
18
|
end
|
data/lib/leap/report.rb
CHANGED
@@ -2,19 +2,28 @@ module Leap
|
|
2
2
|
class Report
|
3
3
|
include XmlSerializer
|
4
4
|
|
5
|
-
attr_reader :committee, :conclusion, :quorum
|
5
|
+
attr_reader :subject, :committee, :conclusion, :quorum
|
6
6
|
|
7
|
-
def initialize(committee, report)
|
7
|
+
def initialize(subject, committee, report)
|
8
8
|
raise ArgumentError, 'Reports must identify themselves' unless committee.is_a?(::Leap::Committee)
|
9
|
+
@subject = subject
|
9
10
|
@committee = committee
|
10
11
|
raise ArgumentError, 'Please report with quorum => conclusion' unless report.is_a?(Hash) and report.length == 1
|
11
12
|
@quorum, @conclusion = report.first
|
12
13
|
end
|
13
14
|
|
15
|
+
def formatted_conclusion
|
16
|
+
return @formatted_conclusion unless @formatted_conclusion.nil?
|
17
|
+
if characteristic = subject.class.characteristics[committee.name]
|
18
|
+
@formatted_conclusion = characteristic.display committee.name => conclusion
|
19
|
+
end
|
20
|
+
@formatted_conclusion ||= conclusion
|
21
|
+
end
|
22
|
+
|
14
23
|
def as_json(*)
|
15
24
|
{
|
16
25
|
'committee' => committee.as_json,
|
17
|
-
'conclusion' =>
|
26
|
+
'conclusion' => formatted_conclusion,
|
18
27
|
'quorum' => quorum.as_json
|
19
28
|
}
|
20
29
|
end
|
@@ -23,7 +32,7 @@ module Leap
|
|
23
32
|
super options do |xml|
|
24
33
|
xml.report do |report_block|
|
25
34
|
committee.to_xml(options.merge :skip_instruct => true, :builder => report_block)
|
26
|
-
report_block.conclusion
|
35
|
+
report_block.conclusion formatted_conclusion, :type => formatted_conclusion.class.to_s.downcase
|
27
36
|
quorum.to_xml(options.merge :skip_instruct => true, :builder => report_block)
|
28
37
|
end
|
29
38
|
end
|
data/lib/leap/subject.rb
CHANGED
@@ -12,7 +12,7 @@ module Leap
|
|
12
12
|
define_method goal do |*considerations|
|
13
13
|
options = considerations.extract_options!
|
14
14
|
@deliberations ||= {}
|
15
|
-
@deliberations[goal] = self.class.decisions[goal].make(
|
15
|
+
@deliberations[goal] = self.class.decisions[goal].make(self, *considerations.push(options))
|
16
16
|
@deliberations[goal][goal] or raise ::Leap::NoSolutionError
|
17
17
|
end
|
18
18
|
end
|
data/test/leap/test_report.rb
CHANGED
@@ -1,22 +1,33 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
+
class Vagabond
|
4
|
+
include Characterizable
|
5
|
+
|
6
|
+
characterize do
|
7
|
+
has :scruples
|
8
|
+
has :tenacity do
|
9
|
+
displays { |t| "ferocious" }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
class Leap::ReportTest < Test::Unit::TestCase
|
4
15
|
context 'to_xml' do
|
5
16
|
should 'serialize to xml' do
|
6
17
|
choc = Leap::Quorum.new('with chocolate chips', {}, Proc.new {})
|
7
18
|
mac = Leap::Quorum.new('with macadamia nuts', {}, Proc.new {})
|
8
|
-
committee = Leap::Committee.new
|
19
|
+
committee = Leap::Committee.new :scruples
|
9
20
|
committee.instance_variable_set :@quorums, [choc, mac]
|
10
21
|
|
11
|
-
report = Leap::Report.new committee, choc => 'good'
|
22
|
+
report = Leap::Report.new Vagabond.new, committee, choc => 'good'
|
12
23
|
|
13
24
|
output = ''
|
14
25
|
report.to_xml(:target => output)
|
15
|
-
assert_equal(
|
26
|
+
assert_equal(<<-XML, output)
|
16
27
|
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
17
28
|
<report>
|
18
29
|
<committee>
|
19
|
-
<name type="string">
|
30
|
+
<name type="string">scruples</name>
|
20
31
|
<quorums type="array">
|
21
32
|
<quorum>
|
22
33
|
<name type="string">with chocolate chips</name>
|
@@ -49,7 +60,75 @@ class Leap::ReportTest < Test::Unit::TestCase
|
|
49
60
|
</complies>
|
50
61
|
</quorum>
|
51
62
|
</report>
|
52
|
-
XML
|
63
|
+
XML
|
64
|
+
end
|
65
|
+
should 'use a custom conclusion' do
|
66
|
+
choc = Leap::Quorum.new('with chocolate chips', {}, Proc.new {})
|
67
|
+
mac = Leap::Quorum.new('with macadamia nuts', {}, Proc.new {})
|
68
|
+
committee = Leap::Committee.new :tenacity
|
69
|
+
committee.instance_variable_set :@quorums, [choc, mac]
|
70
|
+
|
71
|
+
report = Leap::Report.new Vagabond.new, committee, choc => 'tough'
|
72
|
+
|
73
|
+
output = ''
|
74
|
+
report.to_xml :target => output
|
75
|
+
assert_equal(<<-XML, output)
|
76
|
+
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
77
|
+
<report>
|
78
|
+
<committee>
|
79
|
+
<name type="string">tenacity</name>
|
80
|
+
<quorums type="array">
|
81
|
+
<quorum>
|
82
|
+
<name type="string">with chocolate chips</name>
|
83
|
+
<requirements type="array">
|
84
|
+
</requirements>
|
85
|
+
<appreciates type="array">
|
86
|
+
</appreciates>
|
87
|
+
<complies type="array">
|
88
|
+
</complies>
|
89
|
+
</quorum>
|
90
|
+
<quorum>
|
91
|
+
<name type="string">with macadamia nuts</name>
|
92
|
+
<requirements type="array">
|
93
|
+
</requirements>
|
94
|
+
<appreciates type="array">
|
95
|
+
</appreciates>
|
96
|
+
<complies type="array">
|
97
|
+
</complies>
|
98
|
+
</quorum>
|
99
|
+
</quorums>
|
100
|
+
</committee>
|
101
|
+
<conclusion type="string">ferocious</conclusion>
|
102
|
+
<quorum>
|
103
|
+
<name type="string">with chocolate chips</name>
|
104
|
+
<requirements type="array">
|
105
|
+
</requirements>
|
106
|
+
<appreciates type="array">
|
107
|
+
</appreciates>
|
108
|
+
<complies type="array">
|
109
|
+
</complies>
|
110
|
+
</quorum>
|
111
|
+
</report>
|
112
|
+
XML
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'formatted_conclusion' do
|
117
|
+
should 'return the regular conclusion if there is no custom format for the conclusion corresponding characteristic' do
|
118
|
+
choc = Leap::Quorum.new('with chocolate chips', {}, Proc.new {})
|
119
|
+
committee = Leap::Committee.new :scruples
|
120
|
+
committee.instance_variable_set :@quorums, [choc]
|
121
|
+
|
122
|
+
report = Leap::Report.new Vagabond.new, committee, choc => 'good'
|
123
|
+
assert_equal 'good', report.formatted_conclusion
|
124
|
+
end
|
125
|
+
should 'return the formatted conclusion if there is a custom format for the conclusion corresponding characteristic' do
|
126
|
+
choc = Leap::Quorum.new('with chocolate chips', {}, Proc.new {})
|
127
|
+
committee = Leap::Committee.new :tenacity
|
128
|
+
committee.instance_variable_set :@quorums, [choc]
|
129
|
+
|
130
|
+
report = Leap::Report.new Vagabond.new, committee, choc => 'good'
|
131
|
+
assert_equal 'ferocious', report.formatted_conclusion
|
53
132
|
end
|
54
133
|
end
|
55
134
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 5
|
9
|
+
version: 0.4.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andy Rossmeissl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-04 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|