dci-ruby 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/dci-ruby.gemspec +70 -0
- data/example/example.rb +55 -0
- data/lib/dci-ruby/kernel.rb +8 -0
- data/lib/dci-ruby.rb +83 -0
- data/spec/context_spec.rb +64 -0
- data/spec/interaction_spec.rb +26 -0
- data/spec/role_spec.rb +20 -0
- data/spec/roleplayers_spec.rb +46 -0
- data/spec/spec_helper.rb +12 -0
- data/test/helper.rb +18 -0
- data/test/test_dci-ruby.rb +7 -0
- metadata +158 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.5)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rcov (1.0.0)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.11.0)
|
17
|
+
rspec-core (~> 2.11.0)
|
18
|
+
rspec-expectations (~> 2.11.0)
|
19
|
+
rspec-mocks (~> 2.11.0)
|
20
|
+
rspec-core (2.11.1)
|
21
|
+
rspec-expectations (2.11.3)
|
22
|
+
diff-lcs (~> 1.1.3)
|
23
|
+
rspec-mocks (2.11.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
jeweler (~> 1.8.4)
|
31
|
+
rcov
|
32
|
+
rdoc (~> 3.12)
|
33
|
+
rspec (~> 2)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Lorenzo Tello
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= dci-ruby
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to dci-ruby
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Lorenzo Tello. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "dci-ruby"
|
18
|
+
gem.homepage = "http://github.com/ltello/dci-ruby"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Make DCI paradigm available to Ruby applications by enabling developers defining contexts suclassing the new class Context. You define roles inside the definition. Match roles and player objects in context instanciation.}
|
21
|
+
gem.description = %Q{Make DCI paradigm available to Ruby applications}
|
22
|
+
gem.email = "ltello8a@gmail.com"
|
23
|
+
gem.authors = ["Lorenzo Tello"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "dci-ruby #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
data/dci-ruby.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "dci-ruby"
|
8
|
+
s.version = "0.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Lorenzo Tello"]
|
12
|
+
s.date = "2012-10-23"
|
13
|
+
s.description = "Make DCI paradigm available to Ruby applications"
|
14
|
+
s.email = "ltello8a@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"dci-ruby.gemspec",
|
29
|
+
"example/example.rb",
|
30
|
+
"lib/dci-ruby.rb",
|
31
|
+
"lib/dci-ruby/kernel.rb",
|
32
|
+
"spec/context_spec.rb",
|
33
|
+
"spec/interaction_spec.rb",
|
34
|
+
"spec/role_spec.rb",
|
35
|
+
"spec/roleplayers_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_dci-ruby.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/ltello/dci-ruby"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = "1.8.24"
|
44
|
+
s.summary = "Make DCI paradigm available to Ruby applications by enabling developers defining contexts suclassing the new class Context. You define roles inside the definition. Match roles and player objects in context instanciation."
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
51
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
54
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/example/example.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'dci-ruby'
|
2
|
+
|
3
|
+
|
4
|
+
class CheckingAccount
|
5
|
+
attr_reader :account_id
|
6
|
+
attr_accessor :balance
|
7
|
+
|
8
|
+
def initialize(account_id)
|
9
|
+
@account_id, @balance = account_id, 0
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class MoneyTransferContext < Context
|
15
|
+
|
16
|
+
# Roles Definitions
|
17
|
+
|
18
|
+
role :source_account do
|
19
|
+
def run_transfer_of(amount)
|
20
|
+
self.balance -= amount
|
21
|
+
puts "Source Account #{account_id} sent $#{amount} to Target Account #{target_account.account_id}."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
role :target_account do
|
26
|
+
def run_transfer_of(amount)
|
27
|
+
self.balance += amount
|
28
|
+
puts "Target Account #{account_id} received $#{amount} from Source Account #{source_account.account_id}."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Interactions
|
34
|
+
|
35
|
+
def run(amount)
|
36
|
+
puts "Balances Before: #{balances}"
|
37
|
+
source_account.run_transfer_of(amount)
|
38
|
+
target_account.run_transfer_of(amount)
|
39
|
+
puts "Balances After: #{balances}"
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def accounts
|
46
|
+
[source_account, target_account]
|
47
|
+
end
|
48
|
+
|
49
|
+
def balances
|
50
|
+
accounts.map {|account| "$#{account.balance}"}.join(' - ')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
MoneyTransferContext.new(:source_account => CheckingAccount.new(1),
|
55
|
+
:target_account => CheckingAccount.new(2)).run(100)
|
data/lib/dci-ruby.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'dci-ruby/kernel'
|
3
|
+
|
4
|
+
|
5
|
+
class Context
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# Every subclass of Context has is own class and instance method roles defined.
|
10
|
+
# The instance method delegates value to the class.
|
11
|
+
def inherited(subklass)
|
12
|
+
subklass.class_eval do
|
13
|
+
def self.roles; {} end
|
14
|
+
def roles; self.class.roles end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# The macro role is defined to allow a subclass of Context to define roles in its definition.
|
22
|
+
# Every new role redefines the role class method to contain a hash accumulating all defined roles in that subclass.
|
23
|
+
# An accessor to the object playing the new role is also defined and available in every instance of the context subclass.
|
24
|
+
def role(role_key, &block)
|
25
|
+
raise "role name must be a symbol" unless role_key.is_a?(Symbol)
|
26
|
+
updated_roles = roles.merge(role_key => Module.new(&block))
|
27
|
+
singleton_class.class_exec(updated_roles) do |new_roles|
|
28
|
+
remove_method(:roles) rescue nil
|
29
|
+
define_method(:roles) { new_roles }
|
30
|
+
end
|
31
|
+
attr_reader role_key
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# Instances of a defined subclass of Context are initialized checking first that all subclass defined roles
|
38
|
+
# are provided in the creation invocation raising an error if any of them is missing.
|
39
|
+
# Once the previous check is met, every object playing in the context instance is associated to the stated role.
|
40
|
+
def initialize(players={})
|
41
|
+
check_all_roles_provided_in(players)
|
42
|
+
assign_roles_to_players(players)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Checks there is an intented player for every role.
|
49
|
+
# Raises and error message in case of missing roles.
|
50
|
+
def check_all_roles_provided_in(players={})
|
51
|
+
missing_roles = missing_roles(players)
|
52
|
+
raise "missing roles #{missing_roles}" unless missing_roles.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
# The list of roles with no player provided
|
56
|
+
def missing_roles(players={})
|
57
|
+
(roles.keys - players.keys)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Associates every role to the intended player.
|
61
|
+
def assign_roles_to_players(players={})
|
62
|
+
roles.keys.each do |role_key|
|
63
|
+
assign_role_to_player(role_key, players[role_key])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Associates a role to an intended player:
|
68
|
+
# - The object to play the role extends the defined module for that role, so it now respond to the methods
|
69
|
+
# defined in the role definition.
|
70
|
+
# - The object to play the role has access to the context it is playing.
|
71
|
+
# - The object to play the role has access to the rest of players in its context.
|
72
|
+
# - The context instance has access to this new player through a new instance variable defined with the name of the role.
|
73
|
+
def assign_role_to_player(role_key, player)
|
74
|
+
role_module = roles[role_key]
|
75
|
+
other_role_keys = roles.keys - [role_key]
|
76
|
+
player.extend(role_module, ::SingleForwardable)
|
77
|
+
player.singleton_class.class_exec(self) do |context|
|
78
|
+
define_method(:context) {context}
|
79
|
+
end
|
80
|
+
player.def_delegators(:context, *other_role_keys)
|
81
|
+
instance_variable_set(:"@#{role_key}", player)
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Context do
|
4
|
+
|
5
|
+
context "Definition" do
|
6
|
+
context "When Inherit from Context" do
|
7
|
+
before(:all) do
|
8
|
+
class ExampleContext < Context
|
9
|
+
role :rolename do
|
10
|
+
end
|
11
|
+
|
12
|
+
def interaction1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it("A new context subclass is ready to be used...") {ExampleContext.superclass.should be(Context)}
|
18
|
+
it("...in which the developer can define roles...") {ExampleContext.private_methods.should include("role")}
|
19
|
+
it("...but privately inside the class.") {ExampleContext.should_not respond_to(:role)}
|
20
|
+
it("He can also define contextmethods (instance methods) that acts as interactions.") {ExampleContext.public_instance_methods(false).should include('interaction1')}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Use" do
|
25
|
+
context "To use a Context" do
|
26
|
+
before(:all) do
|
27
|
+
class AnotherContext < Context
|
28
|
+
role :role1 do
|
29
|
+
end
|
30
|
+
role :role2 do
|
31
|
+
end
|
32
|
+
|
33
|
+
def interaction1
|
34
|
+
role1
|
35
|
+
end
|
36
|
+
|
37
|
+
def interaction2
|
38
|
+
role1.object_id - role2.object_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@player1, @player2 = Object.new, Object.new
|
42
|
+
@example_context = AnotherContext.new(:role1 => @player1, :role2 => @player2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it("You instanciate it...") {@example_context.class.should be(AnotherContext)}
|
46
|
+
it("...providing a hash of type {:rolename1 => player1, ... }") do
|
47
|
+
expect {AnotherContext.new(@player1, @player2)}.to raise_error
|
48
|
+
end
|
49
|
+
it("...with ALL rolenames as keys...") do
|
50
|
+
expect {AnotherContext.new(:role1 => @player1)}.to raise_error('missing roles role2')
|
51
|
+
end
|
52
|
+
it("...and the objects to play those roles as values.") do
|
53
|
+
[@player1, @player2].should include(@example_context.role1, @example_context.role2)
|
54
|
+
end
|
55
|
+
it("Once instanciated...") {@example_context.class.should be(AnotherContext)}
|
56
|
+
it("...you call an interaction (instance method) on it") {@example_context.should respond_to(:interaction1)}
|
57
|
+
it("...to start interaction among roleplayers inside the context") do
|
58
|
+
@example_context.interaction2.should be_instance_of(Fixnum)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'Interaction' do
|
4
|
+
|
5
|
+
context "Inside a contextmethod(interaction)" do
|
6
|
+
before(:all) do
|
7
|
+
class AnotherContext < Context
|
8
|
+
role :role1 do
|
9
|
+
end
|
10
|
+
role :role2 do
|
11
|
+
end
|
12
|
+
|
13
|
+
def interaction1
|
14
|
+
role1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@player1, @player2 = Object.new, Object.new
|
18
|
+
@example_context = AnotherContext.new(:role1 => @player1, :role2 => @player2)
|
19
|
+
end
|
20
|
+
|
21
|
+
it("The developer has access to all the roleplayers...") {@example_context.interaction1.should be(@player1)}
|
22
|
+
it("...named after the rolenames.") {@example_context.methods.should include('role1', 'role2')}
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
data/spec/role_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'Role' do
|
4
|
+
|
5
|
+
context "When defining roles inside a Context subclass..." do
|
6
|
+
before(:all) do
|
7
|
+
class ExampleContext < Context
|
8
|
+
role :rolename do
|
9
|
+
end
|
10
|
+
role :anotherrolename do
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
it("You can define as many as you want") {ExampleContext.roles.keys.size.should eql(2)}
|
15
|
+
it("Each rolename must be provided as a symbol...") {ExampleContext.roles.keys.should include(:rolename)}
|
16
|
+
it("...and not as a string") {expect {class ExampleContext < Context; role "rolename" do; end; end}.to raise_error}
|
17
|
+
it("A block defining rolemethods can also be provided.") {ExampleContext.roles[:rolename].class.should be(Module)}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe 'RolePlayers' do
|
5
|
+
|
6
|
+
context "Are Ruby objects inside a context instance" do
|
7
|
+
before(:all) do
|
8
|
+
class AnotherContext < Context
|
9
|
+
role :role1 do
|
10
|
+
def rolemethod1
|
11
|
+
:rolemethod1_executed
|
12
|
+
end
|
13
|
+
end
|
14
|
+
role :role2 do
|
15
|
+
def rolemethod2
|
16
|
+
role1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def interaction1
|
21
|
+
role1
|
22
|
+
end
|
23
|
+
|
24
|
+
def interaction2
|
25
|
+
role1.object_id - role2.object_id
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@player1, @player2 = OpenStruct.new(:field1 => 'value1'), OpenStruct.new(:field2 => 'value2')
|
29
|
+
@example_context = AnotherContext.new(:role1 => @player1, :role2 => @player2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it("that besides their normal behaviour...") do
|
33
|
+
@player1.field1.should eql('value1')
|
34
|
+
end
|
35
|
+
it("...also respond to the rolemethods defined in their playing role.") do
|
36
|
+
@example_context.role1.rolemethod1.should eql(:rolemethod1_executed)
|
37
|
+
end
|
38
|
+
it("Roleplayers can access other roleplayers in their context...") do
|
39
|
+
@example_context.role2.rolemethod2.should eql(@example_context.role1)
|
40
|
+
end
|
41
|
+
it("...and even the context itself.") do
|
42
|
+
@example_context.role2.context.should eql(@example_context)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'dci-ruby'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dci-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lorenzo Tello
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-10-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 7
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
version: "2"
|
30
|
+
version_requirements: *id001
|
31
|
+
name: rspec
|
32
|
+
prerelease: false
|
33
|
+
type: :development
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 31
|
41
|
+
segments:
|
42
|
+
- 3
|
43
|
+
- 12
|
44
|
+
version: "3.12"
|
45
|
+
version_requirements: *id002
|
46
|
+
name: rdoc
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 23
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 0
|
59
|
+
- 0
|
60
|
+
version: 1.0.0
|
61
|
+
version_requirements: *id003
|
62
|
+
name: bundler
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 63
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 8
|
75
|
+
- 4
|
76
|
+
version: 1.8.4
|
77
|
+
version_requirements: *id004
|
78
|
+
name: jeweler
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
version_requirements: *id005
|
92
|
+
name: rcov
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
description: Make DCI paradigm available to Ruby applications
|
96
|
+
email: ltello8a@gmail.com
|
97
|
+
executables: []
|
98
|
+
|
99
|
+
extensions: []
|
100
|
+
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- .document
|
106
|
+
- .rspec
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- dci-ruby.gemspec
|
114
|
+
- example/example.rb
|
115
|
+
- lib/dci-ruby.rb
|
116
|
+
- lib/dci-ruby/kernel.rb
|
117
|
+
- spec/context_spec.rb
|
118
|
+
- spec/interaction_spec.rb
|
119
|
+
- spec/role_spec.rb
|
120
|
+
- spec/roleplayers_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_dci-ruby.rb
|
124
|
+
homepage: http://github.com/ltello/dci-ruby
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
138
|
+
segments:
|
139
|
+
- 0
|
140
|
+
version: "0"
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
hash: 3
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
version: "0"
|
150
|
+
requirements: []
|
151
|
+
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.8.24
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Make DCI paradigm available to Ruby applications by enabling developers defining contexts suclassing the new class Context. You define roles inside the definition. Match roles and player objects in context instanciation.
|
157
|
+
test_files: []
|
158
|
+
|