dci 0.2.0 → 0.3.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.
- checksums.yaml +7 -0
- data/COPYING.md +3 -3
- data/HISTORY.md +24 -0
- data/README.md +78 -9
- data/demo/account_example.md +2 -3
- data/demo/applique/dci.rb +2 -0
- data/demo/context.md +43 -0
- data/demo/role.md +45 -0
- data/lib/dci/role.rb +12 -4
- data/lib/dci/version.rb +4 -0
- data/lib/dci.rb +2 -1
- metadata +53 -36
- data/.ruby +0 -43
- data/.yardopts +0 -7
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5b7ac684e438b2b414e153b5b4b93e1ec88949272df8c7127639797244ec2978
|
|
4
|
+
data.tar.gz: f60bf40bf38d3fe9799c62d70fe4593cd5902066930144cf0163dfff27994121
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ef6ba8d455d742eeadbd37c46be2d2c5f3957d7ed8874a163b3ccd0498d36a5d2d041919d4169fe59146379c6f9e8c2b704ef0f0a54795a09b9b9de6bdbfb490
|
|
7
|
+
data.tar.gz: fb5c1a8b929c0a14dee632c59a35fda83ba405ba687dfce3776c8911262917b68e119627284b246ec3184fc3068649db1fd4a505d7476efab17608aa62351c17
|
data/COPYING.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## NOTICES
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### DCI
|
|
6
6
|
|
|
7
|
-
| Project |
|
|
7
|
+
| Project | DCI |
|
|
8
8
|
|-----------|-----------------------------------|
|
|
9
9
|
| Copyright | (c) 2012 Rubyworks |
|
|
10
10
|
| License | (r) BSD-2-Clause |
|
|
11
|
-
| Website |
|
|
11
|
+
| Website | https://github.com/rubyworks/dci |
|
|
12
12
|
|
|
13
13
|
## LICENSES
|
|
14
14
|
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# HISTORY
|
|
2
2
|
|
|
3
|
+
## 0.3.0 | 2026-11-30
|
|
4
|
+
|
|
5
|
+
DCI is brought up to date: it needs Ruby 3.1 or newer, and its
|
|
6
|
+
demonstrations run in CI.
|
|
7
|
+
|
|
8
|
+
Changes:
|
|
9
|
+
|
|
10
|
+
* A role passes keyword arguments on to its player.
|
|
11
|
+
* A role answers `respond_to?` for its player's methods.
|
|
12
|
+
* `DCI::VERSION` is a plain constant.
|
|
13
|
+
* Plain gemspec; the demonstrations are included in the gem.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 0.2.0 | 2012-02-08
|
|
17
|
+
|
|
18
|
+
This release wraps the code in the DCI namepace and improved role
|
|
19
|
+
lookup in Context class.
|
|
20
|
+
|
|
21
|
+
Changes:
|
|
22
|
+
|
|
23
|
+
* Use DCI namespace.
|
|
24
|
+
* Improve context role lookup.
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## 0.1.0 | 2012-02-07
|
|
4
28
|
|
|
5
29
|
This is the initial working version of DCI.
|
data/README.md
CHANGED
|
@@ -1,27 +1,96 @@
|
|
|
1
1
|
# DCI for Ruby
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[
|
|
3
|
+
[Source Code](https://github.com/rubyworks/dci) /
|
|
4
|
+
[Report Issue](https://github.com/rubyworks/dci/issues) /
|
|
5
|
+
[API](https://rubydoc.info/gems/dci)
|
|
6
|
+
[](https://github.com/rubyworks/dci/actions/workflows/ci.yml)
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
## Description
|
|
10
10
|
|
|
11
11
|
The DCI library for Ruby is a fairly faithful implementation of the DCI
|
|
12
|
-
|
|
12
|
+
(Data, Context and Interaction) concepts developed by Trygve Reenskaug
|
|
13
|
+
and James O. Coplien.
|
|
13
14
|
|
|
14
|
-
It
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
It defines two reusable base classes, the Role and the Context. The data
|
|
16
|
+
is any object of yours.
|
|
17
|
+
|
|
18
|
+
It is an experiment more than a tool: a small, working statement of the
|
|
19
|
+
idea, to read and try out.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Synopsis
|
|
23
|
+
|
|
24
|
+
The data is a plain object, which knows nothing of any use case.
|
|
25
|
+
|
|
26
|
+
class Account
|
|
27
|
+
attr_reader :balance
|
|
28
|
+
|
|
29
|
+
def initialize(balance)
|
|
30
|
+
@balance = balance
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def increase_balance(amount)
|
|
34
|
+
@balance += amount
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def decrease_balance(amount)
|
|
38
|
+
@balance -= amount
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
A role is what an object does in a use case. Anything a role doesn't
|
|
43
|
+
define is sent on to the object playing it.
|
|
44
|
+
|
|
45
|
+
class TransferWithdraw < DCI::Role
|
|
46
|
+
def transfer(amount)
|
|
47
|
+
decrease_balance(amount)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class TransferDeposit < DCI::Role
|
|
52
|
+
def transfer(amount)
|
|
53
|
+
increase_balance(amount)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
A context names the roles of a use case, casts objects in them, and
|
|
58
|
+
carries the use case out.
|
|
59
|
+
|
|
60
|
+
class Transfer < DCI::Context
|
|
61
|
+
role :source_account => TransferWithdraw
|
|
62
|
+
role :destination_account => TransferDeposit
|
|
63
|
+
|
|
64
|
+
def initialize(source_account, destination_account)
|
|
65
|
+
self.source_account = source_account
|
|
66
|
+
self.destination_account = destination_account
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def transfer(amount)
|
|
70
|
+
roles.each{ |role| role.transfer(amount) }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
acct1 = Account.new(100)
|
|
75
|
+
acct2 = Account.new(100)
|
|
76
|
+
|
|
77
|
+
Transfer.new(acct1, acct2).transfer(50)
|
|
78
|
+
|
|
79
|
+
acct1.balance #=> 50
|
|
80
|
+
acct2.balance #=> 150
|
|
81
|
+
|
|
82
|
+
The [demonstrations](https://github.com/rubyworks/dci/tree/master/demo)
|
|
83
|
+
have more, and are run as tests with [QED](https://github.com/rubyworks/qed).
|
|
17
84
|
|
|
18
85
|
|
|
19
86
|
## Installation
|
|
20
87
|
|
|
21
|
-
The
|
|
88
|
+
The usual RubyGems install procedure:
|
|
22
89
|
|
|
23
90
|
$ gem install dci
|
|
24
91
|
|
|
92
|
+
DCI needs Ruby 3.1 or newer.
|
|
93
|
+
|
|
25
94
|
|
|
26
95
|
## Copyrights
|
|
27
96
|
|
data/demo/account_example.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Account Balance Transfer
|
|
2
2
|
|
|
3
|
-
The Account Balance
|
|
3
|
+
The Account Balance Transfer is the classic example of using DCI.
|
|
4
4
|
|
|
5
5
|
First we need our Data model. In the example that is the Account class.
|
|
6
6
|
To keep our example simple we will initialize new accounts with
|
|
@@ -43,9 +43,8 @@ and one for depositing money into an account.
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
Now we create a Context which will assign accounts to the roles
|
|
46
|
-
and used to
|
|
46
|
+
and used to perform the transfer.
|
|
47
47
|
|
|
48
|
-
# We can think of a context as setting a scene.
|
|
49
48
|
class Account::Transfer < DCI::Context
|
|
50
49
|
role :source_account => Account::TransferWithdraw
|
|
51
50
|
role :destination_account => Account::TransferDeposit
|
data/demo/applique/dci.rb
CHANGED
data/demo/context.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Context
|
|
2
|
+
|
|
3
|
+
Let's setup a very simple example to run some tests.
|
|
4
|
+
|
|
5
|
+
class ExampleObject
|
|
6
|
+
def say_anything
|
|
7
|
+
"anything"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ExampleRole < DCI::Role
|
|
12
|
+
def say_anything
|
|
13
|
+
@self.say_anything
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class ExampleContext < DCI::Context
|
|
18
|
+
role :player => ExampleRole
|
|
19
|
+
|
|
20
|
+
def initialize(player)
|
|
21
|
+
self.player = player
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def say_anything
|
|
25
|
+
roles.each{ |role| role.say_anything }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
So lets make sure the roles are listed.
|
|
30
|
+
|
|
31
|
+
ExampleContext.roles #=> [:player]
|
|
32
|
+
|
|
33
|
+
Now if subclass the ExampleContext and added a new roll,
|
|
34
|
+
|
|
35
|
+
class AlternateContext < ExampleContext
|
|
36
|
+
role :fanboy => ExampleRole
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Then both roles should be in the the list.
|
|
40
|
+
|
|
41
|
+
AlternateContext.roles #=> [:fanboy, :player]
|
|
42
|
+
|
|
43
|
+
|
data/demo/role.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Role
|
|
2
|
+
|
|
3
|
+
A role is played by an object. Whatever the role doesn't define itself
|
|
4
|
+
is sent on to that object, the player.
|
|
5
|
+
|
|
6
|
+
class Greeter
|
|
7
|
+
def name
|
|
8
|
+
"World"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def greet(greeting: "Hello")
|
|
12
|
+
"#{greeting}, #{name}!"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class LoudRole < DCI::Role
|
|
17
|
+
def shout
|
|
18
|
+
greet(greeting: "HEY").upcase
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
role = LoudRole.new(Greeter.new)
|
|
23
|
+
|
|
24
|
+
The role has its own methods, which call the player's as if they were
|
|
25
|
+
its own.
|
|
26
|
+
|
|
27
|
+
role.shout #=> "HEY, WORLD!"
|
|
28
|
+
|
|
29
|
+
The player's methods can be called on the role too, keyword arguments
|
|
30
|
+
and all.
|
|
31
|
+
|
|
32
|
+
role.name #=> "World"
|
|
33
|
+
role.greet(greeting: "Howdy") #=> "Howdy, World!"
|
|
34
|
+
|
|
35
|
+
So a role responds to whatever its player responds to.
|
|
36
|
+
|
|
37
|
+
role.respond_to?(:shout) #=> true
|
|
38
|
+
role.respond_to?(:name) #=> true
|
|
39
|
+
role.respond_to?(:nope) #=> false
|
|
40
|
+
|
|
41
|
+
And a method neither of them has is a NoMethodError, as usual.
|
|
42
|
+
|
|
43
|
+
expect NoMethodError do
|
|
44
|
+
role.nope
|
|
45
|
+
end
|
data/lib/dci/role.rb
CHANGED
|
@@ -31,7 +31,7 @@ module DCI
|
|
|
31
31
|
# end
|
|
32
32
|
# end
|
|
33
33
|
#
|
|
34
|
-
# class Account::
|
|
34
|
+
# class Account::TransferDeposit < Role
|
|
35
35
|
# def transfer(amount)
|
|
36
36
|
# increase_balance(amount)
|
|
37
37
|
# log "Tranfered into account #{account_id} $#{amount}"
|
|
@@ -40,15 +40,23 @@ module DCI
|
|
|
40
40
|
#
|
|
41
41
|
class Role
|
|
42
42
|
|
|
43
|
-
#
|
|
43
|
+
# A role is played by an object, the player, which the role's methods
|
|
44
|
+
# know as `@self`.
|
|
44
45
|
def initialize(player)
|
|
45
46
|
@self = player
|
|
46
47
|
end
|
|
47
48
|
|
|
49
|
+
# Anything the role doesn't define is sent on to the player, so a
|
|
50
|
+
# role method can call the player's methods as if they were its own.
|
|
48
51
|
#
|
|
49
52
|
# @todo Should use #public_send?
|
|
50
|
-
def method_missing(s, *a, &b)
|
|
51
|
-
@self.__send__(s, *a, &b)
|
|
53
|
+
def method_missing(s, *a, **k, &b)
|
|
54
|
+
@self.__send__(s, *a, **k, &b)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# A role responds to whatever its player responds to.
|
|
58
|
+
def respond_to_missing?(s, include_all=false)
|
|
59
|
+
@self.respond_to?(s, include_all) || super
|
|
52
60
|
end
|
|
53
61
|
|
|
54
62
|
end
|
data/lib/dci/version.rb
ADDED
data/lib/dci.rb
CHANGED
metadata
CHANGED
|
@@ -1,82 +1,99 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dci
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.3.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
|
-
-
|
|
9
|
-
autorequire:
|
|
7
|
+
- Trans
|
|
10
8
|
bindir: bin
|
|
11
9
|
cert_chain: []
|
|
12
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
11
|
dependencies:
|
|
14
12
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
16
|
-
requirement:
|
|
17
|
-
none: false
|
|
13
|
+
name: rake
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
15
|
requirements:
|
|
19
|
-
- -
|
|
16
|
+
- - ">="
|
|
20
17
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
18
|
+
version: '13'
|
|
22
19
|
type: :development
|
|
23
20
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '13'
|
|
25
26
|
- !ruby/object:Gem::Dependency
|
|
26
27
|
name: qed
|
|
27
|
-
requirement:
|
|
28
|
-
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '3.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
29
36
|
requirements:
|
|
30
|
-
- -
|
|
37
|
+
- - ">="
|
|
31
38
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
39
|
+
version: '3.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: ae
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.9'
|
|
33
47
|
type: :development
|
|
34
48
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
36
|
-
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.9'
|
|
54
|
+
description: 'A faithful, if small, implementation of Data, Context and Interaction
|
|
55
|
+
(DCI) for Ruby: a Role class and a Context class.'
|
|
37
56
|
email:
|
|
38
57
|
- transfire@gmail.com
|
|
39
58
|
executables: []
|
|
40
59
|
extensions: []
|
|
41
|
-
extra_rdoc_files:
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
42
62
|
- COPYING.md
|
|
43
63
|
- HISTORY.md
|
|
44
64
|
- README.md
|
|
45
|
-
files:
|
|
46
|
-
- .ruby
|
|
47
|
-
- .yardopts
|
|
48
65
|
- demo/account_example.md
|
|
49
66
|
- demo/applique/dci.rb
|
|
67
|
+
- demo/context.md
|
|
68
|
+
- demo/role.md
|
|
69
|
+
- lib/dci.rb
|
|
50
70
|
- lib/dci/context.rb
|
|
51
71
|
- lib/dci/object.rb
|
|
52
72
|
- lib/dci/role.rb
|
|
53
|
-
- lib/dci.rb
|
|
54
|
-
|
|
55
|
-
- HISTORY.md
|
|
56
|
-
- README.md
|
|
57
|
-
homepage: http://rubyworks.github.com/dci
|
|
73
|
+
- lib/dci/version.rb
|
|
74
|
+
homepage: https://github.com/rubyworks/dci
|
|
58
75
|
licenses:
|
|
59
76
|
- BSD-2-Clause
|
|
60
|
-
|
|
77
|
+
metadata:
|
|
78
|
+
source_code_uri: https://github.com/rubyworks/dci
|
|
79
|
+
bug_tracker_uri: https://github.com/rubyworks/dci/issues
|
|
80
|
+
changelog_uri: https://github.com/rubyworks/dci/blob/master/HISTORY.md
|
|
81
|
+
documentation_uri: https://rubydoc.info/gems/dci
|
|
61
82
|
rdoc_options: []
|
|
62
83
|
require_paths:
|
|
63
84
|
- lib
|
|
64
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
86
|
requirements:
|
|
67
|
-
- -
|
|
87
|
+
- - ">="
|
|
68
88
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
89
|
+
version: '3.1'
|
|
70
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
-
none: false
|
|
72
91
|
requirements:
|
|
73
|
-
- -
|
|
92
|
+
- - ">="
|
|
74
93
|
- !ruby/object:Gem::Version
|
|
75
94
|
version: '0'
|
|
76
95
|
requirements: []
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
signing_key:
|
|
80
|
-
specification_version: 3
|
|
96
|
+
rubygems_version: 3.6.9
|
|
97
|
+
specification_version: 4
|
|
81
98
|
summary: DCI for Ruby
|
|
82
99
|
test_files: []
|
data/.ruby
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
source:
|
|
3
|
-
- Profile
|
|
4
|
-
authors:
|
|
5
|
-
- name: Thomas Sawyer
|
|
6
|
-
email: transfire@gmail.com
|
|
7
|
-
copyrights:
|
|
8
|
-
- holder: Thomas Sawyer
|
|
9
|
-
year: '2012'
|
|
10
|
-
license: BSD-2-Clause
|
|
11
|
-
replacements: []
|
|
12
|
-
alternatives: []
|
|
13
|
-
requirements:
|
|
14
|
-
- name: detroit
|
|
15
|
-
groups:
|
|
16
|
-
- build
|
|
17
|
-
development: true
|
|
18
|
-
- name: qed
|
|
19
|
-
groups:
|
|
20
|
-
- test
|
|
21
|
-
development: true
|
|
22
|
-
dependencies: []
|
|
23
|
-
conflicts: []
|
|
24
|
-
repositories:
|
|
25
|
-
- uri: git@github.com:rubyworks/dci.git
|
|
26
|
-
scm: git
|
|
27
|
-
name: upstream
|
|
28
|
-
resources:
|
|
29
|
-
home: http://rubyworks.github.com/dci
|
|
30
|
-
code: http://github.com/rubyworks/dci
|
|
31
|
-
mail: http://groups.google.com/groups/rubyworks-mailinglist
|
|
32
|
-
extra: {}
|
|
33
|
-
load_path:
|
|
34
|
-
- lib
|
|
35
|
-
revision: 0
|
|
36
|
-
version: 0.2.0
|
|
37
|
-
name: dci
|
|
38
|
-
title: DCI
|
|
39
|
-
summary: DCI for Ruby
|
|
40
|
-
created: '2011-03-04'
|
|
41
|
-
description: Faithful DCI framework for Ruby application development.
|
|
42
|
-
organization: Rubyworks
|
|
43
|
-
date: '2012-02-08'
|