reduxco 1.0.0
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/LICENSE.txt +24 -0
- data/README.rdoc +126 -0
- data/Rakefile +19 -0
- data/lib/reduxco.rb +10 -0
- data/lib/reduxco/callable_ref.rb +142 -0
- data/lib/reduxco/context.rb +243 -0
- data/lib/reduxco/context/callable_table.rb +81 -0
- data/lib/reduxco/context/callstack.rb +74 -0
- data/lib/reduxco/reduxer.rb +41 -0
- data/lib/reduxco/version.rb +4 -0
- data/spec/callable_ref_spec.rb +273 -0
- data/spec/callable_table_spec.rb +174 -0
- data/spec/callstack_spec.rb +128 -0
- data/spec/context_spec.rb +619 -0
- data/spec/rdoc_examples_spec.rb +46 -0
- data/spec/reduxer_spec.rb +88 -0
- data/spec/spec_helper.rb +17 -0
- metadata +69 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'RDoc Examples' do
|
4
|
+
|
5
|
+
describe 'README.rdoc' do
|
6
|
+
|
7
|
+
it 'should obey basic context use' do
|
8
|
+
map = {
|
9
|
+
sum: ->(c){ c[:x] + c[:y] },
|
10
|
+
x: ->(c){ 3 },
|
11
|
+
y: ->(c){ 5 }
|
12
|
+
}
|
13
|
+
|
14
|
+
sum = Reduxco::Reduxer.new(map).reduce(:sum)
|
15
|
+
sum.should == 8
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should override/shadow' do
|
19
|
+
map1 = {
|
20
|
+
message: ->(c){ 'Hello From Map 1' }
|
21
|
+
}
|
22
|
+
|
23
|
+
map2 = {
|
24
|
+
message: ->(c){ 'Hello From Map 2' }
|
25
|
+
}
|
26
|
+
|
27
|
+
msg = Reduxco::Reduxer.new(map1, map2).reduce(:message)
|
28
|
+
msg.should == 'Hello From Map 2'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should super' do
|
32
|
+
map1 = {
|
33
|
+
message: ->(c){ 'Hello From Map 1' }
|
34
|
+
}
|
35
|
+
|
36
|
+
map2 = {
|
37
|
+
message: ->(c){ c.super + ' and Hello From Map 2' }
|
38
|
+
}
|
39
|
+
|
40
|
+
msg = Reduxco::Reduxer.new(map1, map2).reduce(:message)
|
41
|
+
msg.should == 'Hello From Map 1 and Hello From Map 2'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Reduxco::Reduxer do
|
4
|
+
|
5
|
+
describe 'reduce' do
|
6
|
+
|
7
|
+
it 'should alias call to reduce' do
|
8
|
+
reduxer = Reduxco::Reduxer.new
|
9
|
+
reduxer.method(:call).should == reduxer.method(:reduce)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should alias [] to reduce' do
|
13
|
+
reduxer = Reduxco::Reduxer.new
|
14
|
+
reduxer.method(:[]).should == reduxer.method(:reduce)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should delegate reduce to its context call method' do
|
18
|
+
reduxer = Reduxco::Reduxer.new
|
19
|
+
|
20
|
+
refname = double('refname')
|
21
|
+
reduxer.context.should_receive(:call).with(refname)
|
22
|
+
|
23
|
+
reduxer.reduce(refname)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'initialize' do
|
29
|
+
|
30
|
+
it 'should initialize with callable maps' do
|
31
|
+
map1 = double('map1').tap {|m| m.stub(:each)}
|
32
|
+
map2 = double('map2').tap {|m| m.stub(:each)}
|
33
|
+
|
34
|
+
Reduxco::Context.should_receive(:new).with(map1, map2)
|
35
|
+
|
36
|
+
reduxer = Reduxco::Reduxer.new(map1, map2)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should initialize with a copy of a Context when it is the first argument' do
|
40
|
+
context = Reduxco::Context.new
|
41
|
+
context.should_receive(:dup)
|
42
|
+
|
43
|
+
reduxer = Reduxco::Reduxer.new(context)
|
44
|
+
reduxer.context.should_not == context
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'dup' do
|
50
|
+
|
51
|
+
it 'should create a new Reduxer with a new Context' do
|
52
|
+
reduxer = Reduxco::Reduxer.new
|
53
|
+
|
54
|
+
Reduxco::Context.should_receive(:new)
|
55
|
+
dup = reduxer.dup
|
56
|
+
|
57
|
+
dup.context.should_not == reduxer.context
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should dup with the same callable maps.' do
|
61
|
+
map1 = double('map1').tap {|m| m.stub(:each)}
|
62
|
+
map2 = double('map2').tap {|m| m.stub(:each)}
|
63
|
+
|
64
|
+
reduxer = Reduxco::Reduxer.new(map1, map2)
|
65
|
+
|
66
|
+
Reduxco::Context.should_receive(:new).with(map1, map2)
|
67
|
+
|
68
|
+
dup = reduxer.dup
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should dup as the same type' do
|
72
|
+
reduxer = Reduxco::Reduxer.new
|
73
|
+
dup = reduxer.dup
|
74
|
+
dup.should be_kind_of(reduxer.class)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'general' do
|
80
|
+
|
81
|
+
it 'should provide access to the wrapped context' do
|
82
|
+
reduxer = Reduxco::Reduxer.new
|
83
|
+
reduxer.context.should == reduxer.instance_variable_get(:@context)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter {|sf| sf.filename !~ /\/lib\//}
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'reduxco'
|
7
|
+
|
8
|
+
# Require the debugger, if present.
|
9
|
+
begin
|
10
|
+
require 'debugger'
|
11
|
+
rescue LoadError
|
12
|
+
module Kernel
|
13
|
+
def debugger(*args, &block)
|
14
|
+
STDERR.puts "*** Debugger not available."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reduxco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Reinecke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'Reduxco is a general purpose graph reduction calculation engine for
|
15
|
+
those
|
16
|
+
|
17
|
+
non-linear dependency flows that normal pipelines and Rack Middleware-like
|
18
|
+
|
19
|
+
architectures can''t do cleanly.'
|
20
|
+
email:
|
21
|
+
- jreinecke@whitepages.com
|
22
|
+
executables: []
|
23
|
+
extensions: []
|
24
|
+
extra_rdoc_files:
|
25
|
+
- README.rdoc
|
26
|
+
files:
|
27
|
+
- lib/reduxco/callable_ref.rb
|
28
|
+
- lib/reduxco/context/callable_table.rb
|
29
|
+
- lib/reduxco/context/callstack.rb
|
30
|
+
- lib/reduxco/context.rb
|
31
|
+
- lib/reduxco/reduxer.rb
|
32
|
+
- lib/reduxco/version.rb
|
33
|
+
- lib/reduxco.rb
|
34
|
+
- spec/callable_ref_spec.rb
|
35
|
+
- spec/callable_table_spec.rb
|
36
|
+
- spec/callstack_spec.rb
|
37
|
+
- spec/context_spec.rb
|
38
|
+
- spec/rdoc_examples_spec.rb
|
39
|
+
- spec/reduxer_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- README.rdoc
|
42
|
+
- LICENSE.txt
|
43
|
+
- Rakefile
|
44
|
+
homepage: https://github.com/whitepages/reduxco
|
45
|
+
licenses:
|
46
|
+
- BSD
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: A graph reduction calculation engine.
|
69
|
+
test_files: []
|