rpv_core 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -0
- data/bin/rpv +68 -0
- data/lib/rpv/autoload.rb +36 -0
- data/lib/rpv/base_presenter.rb +41 -0
- data/lib/rpv/event_publisher.rb +125 -0
- data/lib/rpv/generators/app_generator.rb +17 -0
- data/lib/rpv/generators/base.rb +130 -0
- data/lib/rpv/generators/presenter_generator.rb +28 -0
- data/lib/rpv/generators/templates/app/README +12 -0
- data/lib/rpv/generators/templates/app/Rakefile +3 -0
- data/lib/rpv/generators/templates/app/app/main.rb +4 -0
- data/lib/rpv/generators/templates/app/app/setup.rb +11 -0
- data/lib/rpv/generators/templates/app/spec/spec_helper.rb +5 -0
- data/lib/rpv/generators/templates/app/tasks/rspec.rake +9 -0
- data/lib/rpv/generators/templates/presenter/presenter.rb.erb +10 -0
- data/lib/rpv/generators/templates/presenter/presenter_spec.rb.erb +22 -0
- data/lib/rpv/inflector.rb +68 -0
- data/lib/rpv/method.rb +13 -0
- data/lib/rpv/method_helper.rb +9 -0
- data/lib/rpv/option_extractor.rb +15 -0
- data/lib/rpv/spec_helper.rb +118 -0
- data/lib/rpv/wiring/base.rb +49 -0
- data/lib/rpv/wiring/callable.rb +20 -0
- data/lib/rpv/wiring/converting.rb +36 -0
- data/lib/rpv/wiring/helpers.rb +23 -0
- data/lib/rpv/wiring/simple.rb +19 -0
- data/lib/rpv/wiring/unidirectional.rb +38 -0
- data/lib/rpv/wiring.rb +4 -0
- data/lib/rpv.rb +20 -0
- data/spec/autoload_spec.rb +24 -0
- data/spec/base_presenter_spec.rb +16 -0
- data/spec/event_publisher_spec.rb +121 -0
- data/spec/files/autoload/b/some_module.rb +2 -0
- data/spec/files/autoload/some_class.rb +3 -0
- data/spec/files/bar/presenter.rb.erb +5 -0
- data/spec/files/bar/view.rb.erb +3 -0
- data/spec/files/foo/Rakefile +0 -0
- data/spec/files/foo/app/main.rb.erb +1 -0
- data/spec/files/foo/app/models/templates/lala.html.erb +2 -0
- data/spec/generators/base_spec.rb +81 -0
- data/spec/generators/presenter_spec.rb +27 -0
- data/spec/method_helper_spec.rb +19 -0
- data/spec/method_spec.rb +12 -0
- data/spec/option_extractor_spec.rb +22 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_helper_spec.rb +15 -0
- data/spec/wiring/base_spec.rb +17 -0
- data/spec/wiring/callable_spec.rb +50 -0
- data/spec/wiring/helpers_spec.rb +29 -0
- data/spec/wiring/simple_spec.rb +47 -0
- data/spec/wiring/unidirectional_spec.rb +46 -0
- data/tasks/rdoc.rake +10 -0
- data/tasks/rspec.rake +10 -0
- metadata +118 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rpv/spec_helper'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "mock_event_publisher" do
|
4
|
+
it "should have null object like behaviour" do
|
5
|
+
m = mock_event_publisher
|
6
|
+
lambda { m.dfdskfsa.sadf.sfa.sadfasfd = 1 }.should_not raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fire events" do
|
10
|
+
v = mock_event_publisher { |m| m.fires :foo }
|
11
|
+
p = mock_block("p") { |m| m.should_receive(:bar) }
|
12
|
+
v.subscribe :foo, RPV::Method.new(p, :bar)
|
13
|
+
v.do_fire(:foo)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'rpv/wiring/base'
|
4
|
+
|
5
|
+
describe "base wiring" do
|
6
|
+
it "should not accept model and presenter at the same time" do
|
7
|
+
lambda { RPV::Wiring::Base.new :view => "bar.text", :model => "foo", :presenter => "lala" }.should raise_error(ArgumentError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should match view against args" do
|
11
|
+
wiring = RPV::Wiring::Base.new :view => "bar.text", :model => "foo"
|
12
|
+
wiring.view_match(:only => /^bar\.(.*)/).should be_true
|
13
|
+
wiring.view_match(:only => /^bar\.(.*)/, :except => /text$/).should be_false
|
14
|
+
wiring.model_match(:except => /foo/).should be_false
|
15
|
+
wiring.view_match().should be_true
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'rpv/wiring/callable'
|
4
|
+
|
5
|
+
describe "callable wiring" do
|
6
|
+
share_examples_for "Both" do
|
7
|
+
it "should call the to view block" do
|
8
|
+
@view.should_receive(:foo=).with("to_view")
|
9
|
+
@model.should_receive(:bar).and_return('')
|
10
|
+
@wiring.update_view(@model, @view, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should call the from view block" do
|
14
|
+
@view.should_receive(:foo).and_return('')
|
15
|
+
@model.should_receive(:bar=).with("from_view")
|
16
|
+
@wiring.update_model(@model, @view, nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "using a Proc" do
|
21
|
+
before(:all) do
|
22
|
+
@view = mock('view')
|
23
|
+
@model = mock('model')
|
24
|
+
@wiring = RPV::Wiring::Callable.new :view => "foo", :model => "bar",
|
25
|
+
:to_view => lambda { |v| "to_view" },
|
26
|
+
:from_view => lambda { |v| "from_view" }
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like "Both"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "using a method" do
|
33
|
+
before(:each) do
|
34
|
+
converter = mock_block("converter") do |m|
|
35
|
+
m.stub(:to_view).and_return("to_view")
|
36
|
+
m.stub(:from_view).and_return("from_view")
|
37
|
+
end
|
38
|
+
@view = mock('view')
|
39
|
+
@model = mock('model')
|
40
|
+
@wiring = RPV::Wiring::Callable.new :view => "foo", :model => "bar",
|
41
|
+
:to_view => RPV::Method.new(converter, :to_view),
|
42
|
+
:from_view => RPV::Method.new(converter, :from_view)
|
43
|
+
end
|
44
|
+
|
45
|
+
it_should_behave_like "Both"
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'rpv/wiring/helpers'
|
4
|
+
|
5
|
+
describe "wiring helpers" do
|
6
|
+
before :all do
|
7
|
+
@klass = Class.new do
|
8
|
+
include RPV::Wiring::WireHelpers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "simple" do
|
13
|
+
it "should add a simple wiring" do
|
14
|
+
@klass.simple(:view => "a", :model => "b").should be_kind_of(RPV::Wiring::Simple)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "unidirectional" do
|
19
|
+
it "should add a unidirectional wiring" do
|
20
|
+
@klass.unidirectional(@klass.simple(:view => "a", :model => "b"), :view_only).should be_kind_of(RPV::Wiring::Unidirectional)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "callable" do
|
25
|
+
it "should add a simple wiring" do
|
26
|
+
@klass.callable(:view => "a", :model => "b").should be_kind_of(RPV::Wiring::Callable)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'rpv/wiring/simple'
|
4
|
+
|
5
|
+
describe "simple wiring" do
|
6
|
+
before(:all) do
|
7
|
+
@view = mock('view')
|
8
|
+
@presenter = mock('presenter')
|
9
|
+
@model = mock('model')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should update the view" do
|
13
|
+
str = "dlksaf"
|
14
|
+
str1 = "ldksafdsalfkjasd"
|
15
|
+
|
16
|
+
@view.stub_chain(:bar, :text=)
|
17
|
+
@view.should_receive(:foo=).with(str1)
|
18
|
+
@model.should_receive(:foo).and_return(str)
|
19
|
+
@presenter.should_receive(:bar).and_return(str1)
|
20
|
+
|
21
|
+
wiring = RPV::Wiring::Simple.new :view => "bar.text", :model => "foo"
|
22
|
+
wiring.update_view(@model, @view, @presenter)
|
23
|
+
|
24
|
+
wiring = RPV::Wiring::Simple.new :view => "foo", :presenter => "bar"
|
25
|
+
wiring.update_view(@model, @view, @presenter)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should update the model" do
|
29
|
+
str = "dlksaf"
|
30
|
+
|
31
|
+
@view.stub_chain(:bar, :text).and_return(str)
|
32
|
+
@model.should_receive(:foo=).with(str)
|
33
|
+
|
34
|
+
wiring = RPV::Wiring::Simple.new :view => "bar.text", :model => "foo"
|
35
|
+
wiring.update_model(@model, @view, nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should update the presenter" do
|
39
|
+
str = "dlksaf"
|
40
|
+
|
41
|
+
@view.stub_chain(:bar, :text).and_return(str)
|
42
|
+
@presenter.should_receive(:foo=).with(str)
|
43
|
+
|
44
|
+
wiring = RPV::Wiring::Simple.new :view => "bar.text", :presenter => "foo"
|
45
|
+
wiring.update_presenter(nil, @view, @presenter)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
require 'rpv/wiring/unidirectional'
|
4
|
+
|
5
|
+
def call_all(wiring)
|
6
|
+
wiring.update_model()
|
7
|
+
wiring.update_presenter()
|
8
|
+
wiring.update_view()
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "unidirectional wiring" do
|
12
|
+
it "should not call update_(model|presenter)" do
|
13
|
+
wiring = RPV::Wiring::Unidirectional.new(m = mock('wiring'), :view_only)
|
14
|
+
m.should_not_receive(:update_model)
|
15
|
+
m.should_not_receive(:update_presenter)
|
16
|
+
m.should_receive(:update_view)
|
17
|
+
call_all(wiring)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not call update_(view|presenter)" do
|
21
|
+
wiring = RPV::Wiring::Unidirectional.new(m = mock('wiring'), :model_only)
|
22
|
+
m.should_receive(:update_model)
|
23
|
+
m.should_not_receive(:update_presenter)
|
24
|
+
m.should_not_receive(:update_view)
|
25
|
+
call_all(wiring)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not call update_(view|model)" do
|
29
|
+
wiring = RPV::Wiring::Unidirectional.new(m = mock('wiring'), :presenter_only)
|
30
|
+
m.should_not_receive(:update_model)
|
31
|
+
m.should_receive(:update_presenter)
|
32
|
+
m.should_not_receive(:update_view)
|
33
|
+
call_all(wiring)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should proxy the matchers" do
|
37
|
+
args = {:only => "something"}
|
38
|
+
wiring = RPV::Wiring::Unidirectional.new(m = mock('wiring'), :presenter_only)
|
39
|
+
m.should_receive(:view_match).with(args)
|
40
|
+
m.should_receive(:model_match).with(args)
|
41
|
+
m.should_receive(:presenter_match).with(args)
|
42
|
+
wiring.view_match(args)
|
43
|
+
wiring.model_match(args)
|
44
|
+
wiring.presenter_match(args)
|
45
|
+
end
|
46
|
+
end
|
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rdoc/task'
|
2
|
+
|
3
|
+
RDoc::Task.new do |rdoc|
|
4
|
+
rdoc.main = "Readme.rdoc"
|
5
|
+
rdoc.rdoc_dir = "doc"
|
6
|
+
rdoc.title = "RPV"
|
7
|
+
rdoc.rdoc_files.include("Readme.rdoc")
|
8
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
9
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
10
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run all specs"
|
5
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
6
|
+
t.spec_opts = ["--colour", "--format progress", "--loadby mtime"]
|
7
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
8
|
+
t.libs = [File.dirname(__FILE__) + '/../lib']
|
9
|
+
end
|
10
|
+
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpv_core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Martin Vielsmaier
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-07 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A simple, modular framework for implementing the Passive View pattern. This pattern descended from the Model View Presenter pattern.
|
22
|
+
email: martin.vielsmaier@gmail.com
|
23
|
+
executables:
|
24
|
+
- rpv
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- Rakefile
|
31
|
+
- spec/wiring/base_spec.rb
|
32
|
+
- spec/wiring/simple_spec.rb
|
33
|
+
- spec/wiring/callable_spec.rb
|
34
|
+
- spec/wiring/unidirectional_spec.rb
|
35
|
+
- spec/wiring/helpers_spec.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/method_spec.rb
|
38
|
+
- spec/base_presenter_spec.rb
|
39
|
+
- spec/spec_helper_spec.rb
|
40
|
+
- spec/autoload_spec.rb
|
41
|
+
- spec/files/autoload/some_class.rb
|
42
|
+
- spec/files/autoload/b/some_module.rb
|
43
|
+
- spec/files/bar/view.rb.erb
|
44
|
+
- spec/files/bar/presenter.rb.erb
|
45
|
+
- spec/files/foo/app/main.rb.erb
|
46
|
+
- spec/files/foo/app/models/templates/lala.html.erb
|
47
|
+
- spec/files/foo/Rakefile
|
48
|
+
- spec/option_extractor_spec.rb
|
49
|
+
- spec/event_publisher_spec.rb
|
50
|
+
- spec/generators/base_spec.rb
|
51
|
+
- spec/generators/presenter_spec.rb
|
52
|
+
- spec/method_helper_spec.rb
|
53
|
+
- tasks/rspec.rake
|
54
|
+
- tasks/rdoc.rake
|
55
|
+
- lib/rpv.rb
|
56
|
+
- lib/rpv/wiring/unidirectional.rb
|
57
|
+
- lib/rpv/wiring/base.rb
|
58
|
+
- lib/rpv/wiring/simple.rb
|
59
|
+
- lib/rpv/wiring/helpers.rb
|
60
|
+
- lib/rpv/wiring/converting.rb
|
61
|
+
- lib/rpv/wiring/callable.rb
|
62
|
+
- lib/rpv/spec_helper.rb
|
63
|
+
- lib/rpv/wiring.rb
|
64
|
+
- lib/rpv/inflector.rb
|
65
|
+
- lib/rpv/method_helper.rb
|
66
|
+
- lib/rpv/event_publisher.rb
|
67
|
+
- lib/rpv/base_presenter.rb
|
68
|
+
- lib/rpv/autoload.rb
|
69
|
+
- lib/rpv/option_extractor.rb
|
70
|
+
- lib/rpv/generators/presenter_generator.rb
|
71
|
+
- lib/rpv/generators/base.rb
|
72
|
+
- lib/rpv/generators/app_generator.rb
|
73
|
+
- lib/rpv/generators/templates/app/tasks/rspec.rake
|
74
|
+
- lib/rpv/generators/templates/app/spec/spec_helper.rb
|
75
|
+
- lib/rpv/generators/templates/app/app/main.rb
|
76
|
+
- lib/rpv/generators/templates/app/app/setup.rb
|
77
|
+
- lib/rpv/generators/templates/app/Rakefile
|
78
|
+
- lib/rpv/generators/templates/app/README
|
79
|
+
- lib/rpv/generators/templates/presenter/presenter.rb.erb
|
80
|
+
- lib/rpv/generators/templates/presenter/presenter_spec.rb.erb
|
81
|
+
- lib/rpv/method.rb
|
82
|
+
- bin/rpv
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://moserei.de
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.3.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: A simple framework for implementing the Passive View pattern.
|
117
|
+
test_files: []
|
118
|
+
|