dci-ruby 0.4.1 → 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/README.rdoc +15 -3
- data/VERSION +1 -1
- data/dci-ruby.gemspec +3 -3
- data/{example/example.rb → examples/money_transfer.rb} +3 -2
- data/lib/dci-ruby.rb +16 -3
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
= dci-ruby
|
2
2
|
|
3
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.
|
4
|
+
This gem makes Data-Context-Interaction paradigm ready to be used in your Ruby application. See also (http://rubysource.com/dci-the-evolution-of-the-object-oriented-paradigm/).
|
5
5
|
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
9
|
-
Install as usual, either with rubygems
|
9
|
+
Install as usual, either with rubygems
|
10
10
|
gem install dci-ruby
|
11
|
-
or
|
11
|
+
or including it in your Gemfile and then running bundle install:
|
12
12
|
# Gemfile
|
13
13
|
gem "dci-ruby"
|
14
14
|
|
@@ -37,6 +37,10 @@ dci-ruby gives you the class Context to inherit from to create your own contexts
|
|
37
37
|
def run(amount)
|
38
38
|
source_account.transfer(amount)
|
39
39
|
end
|
40
|
+
|
41
|
+
def run_default
|
42
|
+
source_account.transfer(default_amount)
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
Every context defines some roles to be played by external objects (players) and their interactions. This way
|
@@ -51,7 +55,15 @@ Use the defined contexts in your application, instantiating them wherever you ne
|
|
51
55
|
Role player objects (the two account instances above) respond to their corresponding role methods inside the context.
|
52
56
|
Moreover, every role player has access to the rest of role players. That's why target_account is reachable inside source_account#transfer
|
53
57
|
rolemethod.
|
58
|
+
When instanciating a Context, the extra no-role pairs given as arguments are read-only attributes accessible inside the instance:
|
59
|
+
|
60
|
+
MoneyTransfer.new(:source_account => Account.new(1),
|
61
|
+
:target_account => Account.new(2),
|
62
|
+
:default_amount => 500).run_default
|
63
|
+
|
64
|
+
here, default_amount is not a roleplayer (has no associated role) but is still accessible in the interactions.
|
54
65
|
|
66
|
+
See the examples[https://github.com/ltello/dci-ruby/tree/master/examples] folder for examples of use and the DCI-Sample[https://github.com/ltello/DCI-Sample] repository for a sample application using DCI through this gem.
|
55
67
|
|
56
68
|
== Copyright
|
57
69
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/dci-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "dci-ruby"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
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"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-25"
|
13
13
|
s.description = "Make DCI paradigm available to Ruby applications"
|
14
14
|
s.email = "ltello8a@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"dci-ruby.gemspec",
|
29
|
-
"
|
29
|
+
"examples/money_transfer.rb",
|
30
30
|
"lib/dci-ruby.rb",
|
31
31
|
"lib/dci-ruby/kernel.rb",
|
32
32
|
"spec/context_spec.rb",
|
@@ -32,7 +32,7 @@ class MoneyTransferContext < Context
|
|
32
32
|
|
33
33
|
# Interactions
|
34
34
|
|
35
|
-
def run
|
35
|
+
def run
|
36
36
|
puts "Balances Before: #{balances}"
|
37
37
|
source_account.run_transfer_of(amount)
|
38
38
|
target_account.run_transfer_of(amount)
|
@@ -52,4 +52,5 @@ class MoneyTransferContext < Context
|
|
52
52
|
end
|
53
53
|
|
54
54
|
MoneyTransferContext.new(:source_account => CheckingAccount.new(1),
|
55
|
-
:target_account => CheckingAccount.new(2)
|
55
|
+
:target_account => CheckingAccount.new(2),
|
56
|
+
:amount => 500).run
|
data/lib/dci-ruby.rb
CHANGED
@@ -37,9 +37,12 @@ class Context
|
|
37
37
|
# Instances of a defined subclass of Context are initialized checking first that all subclass defined roles
|
38
38
|
# are provided in the creation invocation raising an error if any of them is missing.
|
39
39
|
# Once the previous check is met, every object playing in the context instance is associated to the stated role.
|
40
|
-
|
41
|
-
|
40
|
+
# Non players args are associated to instance_variables and readers defined.
|
41
|
+
def initialize(args={})
|
42
|
+
check_all_roles_provided_in!(args)
|
43
|
+
players, noplayers = args.partition {|key, value| roles.keys.include?(key)}.map {|group| Hash[*group.flatten]}
|
42
44
|
assign_roles_to_players(players)
|
45
|
+
define_attr_readers_for_no_players(noplayers)
|
43
46
|
end
|
44
47
|
|
45
48
|
|
@@ -47,7 +50,7 @@ class Context
|
|
47
50
|
|
48
51
|
# Checks there is an intented player for every role.
|
49
52
|
# Raises and error message in case of missing roles.
|
50
|
-
def check_all_roles_provided_in(players={})
|
53
|
+
def check_all_roles_provided_in!(players={})
|
51
54
|
missing_roles = missing_roles(players)
|
52
55
|
raise "missing roles #{missing_roles}" unless missing_roles.empty?
|
53
56
|
end
|
@@ -80,4 +83,14 @@ class Context
|
|
80
83
|
player.def_delegators(:context, *other_role_keys)
|
81
84
|
instance_variable_set(:"@#{role_key}", player)
|
82
85
|
end
|
86
|
+
|
87
|
+
def define_attr_readers_for_no_players(vars={})
|
88
|
+
vars.each do |name, value|
|
89
|
+
instance_variable_set(:"@#{name}", value)
|
90
|
+
singleton_class.class_exec(name.to_sym) do |varkey|
|
91
|
+
attr_reader varkey
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
83
96
|
end
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
7
|
- 1
|
10
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lorenzo Tello
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-10-
|
18
|
+
date: 2012-10-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -111,7 +111,7 @@ files:
|
|
111
111
|
- Rakefile
|
112
112
|
- VERSION
|
113
113
|
- dci-ruby.gemspec
|
114
|
-
-
|
114
|
+
- examples/money_transfer.rb
|
115
115
|
- lib/dci-ruby.rb
|
116
116
|
- lib/dci-ruby/kernel.rb
|
117
117
|
- spec/context_spec.rb
|