leap 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{leap}
8
- s.version = "0.3.3"
8
+ s.version = "0.4.0"
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-07-07}
12
+ s.date = %q{2010-07-16}
13
13
  s.description = %q{Leap to conclusions}
14
14
  s.email = %q{andy@rossmeissl.net}
15
15
  s.extra_rdoc_files = [
@@ -2,6 +2,7 @@ require 'active_support/version'
2
2
  %w{
3
3
  active_support/core_ext/hash/slice
4
4
  active_support/core_ext/array/wrap
5
+ active_support/core_ext/array/extract_options
5
6
  }.each do |active_support_3_requirement|
6
7
  require active_support_3_requirement
7
8
  end if ActiveSupport::VERSION::MAJOR == 3
@@ -7,9 +7,9 @@ module Leap
7
7
  @quorums = []
8
8
  end
9
9
 
10
- def report(characteristics, considerations)
10
+ def report(characteristics, considerations, options = {})
11
11
  quorums.grab do |quorum|
12
- next unless quorum.satisfied_by? characteristics
12
+ next unless quorum.satisfied_by? characteristics and quorum.complies_with? Array.wrap(options[:comply])
13
13
  if conclusion = quorum.acknowledge(characteristics.slice(*quorum.characteristics), considerations.dup)
14
14
  ::Leap::Report.new self, quorum => conclusion
15
15
  end
@@ -21,8 +21,8 @@ module Leap
21
21
  @quorums << ::Leap::Quorum.new(name, options, blk)
22
22
  end
23
23
 
24
- def default(&blk)
25
- quorum 'default', {}, &blk
24
+ def default(options = {}, &blk)
25
+ quorum 'default', options, &blk
26
26
  end
27
27
  end
28
28
  end
@@ -9,8 +9,9 @@ module Leap
9
9
  end
10
10
 
11
11
  def make(characteristics, *considerations)
12
+ options = considerations.extract_options!
12
13
  committees.reject { |c| characteristics.keys.include? c.name }.reverse.inject(Deliberation.new(characteristics)) do |deliberation, committee|
13
- if report = committee.report(deliberation.characteristics, considerations)
14
+ if report = committee.report(deliberation.characteristics, considerations, options)
14
15
  deliberation.reports.unshift report
15
16
  deliberation.characteristics[committee.name] = report.conclusion
16
17
  end
@@ -1,10 +1,11 @@
1
1
  module Leap
2
2
  class Quorum
3
- attr_reader :name, :requirements, :supplements, :process
3
+ attr_reader :name, :requirements, :supplements, :process, :compliance
4
4
  def initialize(name, options, blk)
5
5
  @name = name
6
6
  @requirements = Array.wrap options[:needs]
7
7
  @supplements = Array.wrap options[:appreciates]
8
+ @compliance = Array.wrap options[:complies]
8
9
  @process = blk
9
10
  end
10
11
 
@@ -12,6 +13,10 @@ module Leap
12
13
  (requirements - characteristics.keys).empty?
13
14
  end
14
15
 
16
+ def complies_with?(guidelines)
17
+ (guidelines - compliance).empty?
18
+ end
19
+
15
20
  def acknowledge(characteristics, considerations)
16
21
  considerations.unshift characteristics
17
22
  process.call(*considerations[0...process.arity])
@@ -9,8 +9,9 @@ module Leap
9
9
  decisions[goal] = ::Leap::Decision.new goal, options
10
10
  Blockenspiel.invoke(blk, decisions[goal])
11
11
  define_method goal do |*considerations|
12
+ options = considerations.extract_options!
12
13
  @deliberations ||= {}
13
- @deliberations[goal] = self.class.decisions[goal].make send(self.class.decisions[goal].signature_method), *considerations
14
+ @deliberations[goal] = self.class.decisions[goal].make(send(self.class.decisions[goal].signature_method), *considerations.push(options))
14
15
  @deliberations[goal][goal]
15
16
  end
16
17
  end
@@ -36,10 +36,10 @@ class Person
36
36
  decide :lucky_number, :with => :characteristics do
37
37
  committee :lucky_number do
38
38
  quorum 'super magic method', :needs => [:magic_integer, :magic_float] do |characteristics|
39
- characteristics[:magic_integer] + characteristics[:magic_float]
39
+ characteristics[:magic_integer] + characteristics[:magic_float].ceil
40
40
  end
41
41
 
42
- quorum 'normal magic method', :needs => :magic_integer do |characteristics|
42
+ quorum 'normal magic method', :needs => :magic_integer, :complies => :ipa do |characteristics|
43
43
  characteristics[:magic_integer] ** 2
44
44
  end
45
45
  end
@@ -53,14 +53,14 @@ class Person
53
53
  characteristics[:age] + 1
54
54
  end
55
55
 
56
- default do
56
+ default :complies => :ipa do
57
57
  0
58
58
  end
59
59
  end
60
60
 
61
61
  committee :magic_float do
62
62
  quorum 'ancient recipe', :needs => :name do |characteristics|
63
- ('A'..'Z').to_a.index(characteristics[:name].chars.to_a.first) / ('A'..'Z').to_a.index(characteristics[:name].chars.to_a.last)
63
+ ('A'..'Z').to_a.index(characteristics[:name].chars.to_a.first).to_f / ('A'..'Z').to_a.index(characteristics[:name].chars.to_a.last).to_f
64
64
  end
65
65
  end
66
66
 
@@ -46,6 +46,20 @@ class TestLeap < Test::Unit::TestCase
46
46
  end
47
47
  end
48
48
 
49
+ context "A named person" do
50
+ setup do
51
+ @person = Person.new :name => 'Matz'
52
+ end
53
+
54
+ should 'have access to the super magic method' do
55
+ assert_equal 1, @person.lucky_number
56
+ end
57
+
58
+ should 'be able to stay in compliance with International Psychics Association guidelines' do
59
+ assert_equal 0, @person.lucky_number(:comply => :ipa)
60
+ end
61
+ end
62
+
49
63
  context "A generic place" do
50
64
  setup do
51
65
  @place = Place.new
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
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-07-07 00:00:00 -04:00
18
+ date: 2010-07-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency