dci-ruby 0.4.0 → 0.4.1
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/README.rdoc +52 -11
- data/VERSION +1 -1
- data/dci-ruby.gemspec +2 -4
- metadata +3 -5
- data/test/helper.rb +0 -18
- data/test/test_dci-ruby.rb +0 -7
data/README.rdoc
CHANGED
@@ -1,16 +1,57 @@
|
|
1
1
|
= dci-ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
Trygve Reenskaug, the parent of MVC, proposes an evolution to traditional OO paradigm. (http://www.artima.com/articles/dci_vision.html).
|
4
|
+
This gem makes Data-Context-Interaction paradigm ready to be used in your Ruby application.
|
5
|
+
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Install as usual, either with rubygems or including it in your Gemfile and running bundle install:
|
10
|
+
gem install dci-ruby
|
11
|
+
or
|
12
|
+
# Gemfile
|
13
|
+
gem "dci-ruby"
|
14
|
+
|
15
|
+
|
16
|
+
== Use
|
17
|
+
|
18
|
+
dci-ruby gives you the class Context to inherit from to create your own contexts:
|
19
|
+
|
20
|
+
class MoneyTransfer < Context
|
21
|
+
|
22
|
+
# Roles
|
23
|
+
role :source_account do
|
24
|
+
def transfer(amount)
|
25
|
+
balance -= amount
|
26
|
+
target_account.get_transfer(amount)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
role :target_account do
|
31
|
+
def get_transfer(amount)
|
32
|
+
balance += amount
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Interactions
|
37
|
+
def run(amount)
|
38
|
+
source_account.transfer(amount)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Every context defines some roles to be played by external objects (players) and their interactions. This way
|
43
|
+
you have the whole agents and operations in a user case wrapped in just one entity instead of spreaded througout the
|
44
|
+
whole application code.
|
45
|
+
|
46
|
+
Use the defined contexts in your application, instantiating them wherever you need them in your code:
|
47
|
+
|
48
|
+
MoneyTransfer.new(:source_account => Account.new(1),
|
49
|
+
:target_account => Account.new(2)).run(100)
|
50
|
+
|
51
|
+
Role player objects (the two account instances above) respond to their corresponding role methods inside the context.
|
52
|
+
Moreover, every role player has access to the rest of role players. That's why target_account is reachable inside source_account#transfer
|
53
|
+
rolemethod.
|
54
|
+
|
14
55
|
|
15
56
|
== Copyright
|
16
57
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/dci-ruby.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dci-ruby"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lorenzo Tello"]
|
@@ -33,9 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"spec/interaction_spec.rb",
|
34
34
|
"spec/role_spec.rb",
|
35
35
|
"spec/roleplayers_spec.rb",
|
36
|
-
"spec/spec_helper.rb"
|
37
|
-
"test/helper.rb",
|
38
|
-
"test/test_dci-ruby.rb"
|
36
|
+
"spec/spec_helper.rb"
|
39
37
|
]
|
40
38
|
s.homepage = "http://github.com/ltello/dci-ruby"
|
41
39
|
s.licenses = ["MIT"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dci-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lorenzo Tello
|
@@ -119,8 +119,6 @@ files:
|
|
119
119
|
- spec/role_spec.rb
|
120
120
|
- spec/roleplayers_spec.rb
|
121
121
|
- spec/spec_helper.rb
|
122
|
-
- test/helper.rb
|
123
|
-
- test/test_dci-ruby.rb
|
124
122
|
homepage: http://github.com/ltello/dci-ruby
|
125
123
|
licenses:
|
126
124
|
- MIT
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'dci-ruby'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|