drsi 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e2a89f6f00a413fd3ae85e494e75e0f4bcc4aac
4
- data.tar.gz: b44a051e6678c13077ae65a55e8c11ba36530128
3
+ metadata.gz: 6b99bdc02a78b72391449fe80e587f114dc2fca0
4
+ data.tar.gz: 707d75c55602ea782f5fdda5441c475f263de7bd
5
5
  SHA512:
6
- metadata.gz: abd2d518e9b8952cfff3d150e323e0c440529aadf51c5dc2d2df388c8e93353d86bdd542faeaaeb276635ca503ce1cfa48b7bc8a43f1a8c94fa3facf18a7fb40
7
- data.tar.gz: eae8418a3b0e7949b569cc73a510998d6a7a358ce4836d1548eb5c713b31ee0b79fca8c69cf51b7641c93bfa72c41e547b9edf2bc5393108e7faf01b487ec7aa
6
+ metadata.gz: 6a994734ded3c5039e348dc4fcd2daa40f2927b8a48606daf6bc8fa01d3c8dc2113030fb05faa82279a2391ec8f23df287d061afeb76e2bfa90f48e2fc6f43b5
7
+ data.tar.gz: 3831df641d260d23c583a1d79d93870cc81c8ef82c336b94703187bfe7693717da83376506e277ca4b889c943ac5eb26cf8c15cfb87b3d4cd812700ae2468bc1
data/README.md CHANGED
@@ -69,9 +69,9 @@ Inside a context instance, every player object incorporates the behaviour (metho
69
69
  The Account instances above are players. They are accesible inside #run through #source_account and #target_account private methods.
70
70
  Also, every role player has private access to the rest of role players in the context.
71
71
 
72
- Unlike the Presenter approach in dci-ruby (where the object to play a role and the one inside the context playing it are associated but different), this extending/unextending approach preserves unique identity of objects playing roles.
72
+ Unlike the Presenter approach in dci-ruby (where the object to play a role and the one inside the context playing it are associated but different), this injection approach preserves unique identity of objects playing roles.
73
73
 
74
- When instanciating a Context, the extra no-role pairs given as arguments are read-only attributes accessible via #settings:
74
+ When instantiating a Context, the extra no-role pairs given as arguments are read-only attributes accessible via #settings:
75
75
 
76
76
  MoneyTransfer[:source_account => Account.new(1),
77
77
  :target_account => Account.new(2),
@@ -8,11 +8,18 @@ require 'drsi/module'
8
8
  # reusing the empty ones or adding and extending new ones when it is needed.
9
9
  module Rolable
10
10
 
11
- # Make an object play the role defined as a module in 'mod'
12
- def __play_role!(role_klass, context)
11
+ # Make an object play (in the given 'context') the role defined as a module in 'role_mod':
12
+ # - Get or extend a new empty role module,
13
+ # - Copy role_mod instance_methods into it,
14
+ # - Inject context and settings methods.
15
+ def __play_role!(role_mod, a_context)
13
16
  new_role = __next_empty_role
14
- new_role.__copy_instance_methods_from(role_klass)
15
- new_role.send(:define_method, :context) {context}
17
+ new_role.__copy_instance_methods_from(role_mod)
18
+ new_role.class_exec(a_context) do |the_context|
19
+ private
20
+ define_method(:context) {the_context}
21
+ define_method(:settings) {|*keys| context.send(:settings, *keys)}
22
+ end
16
23
  end
17
24
 
18
25
  # Make an object stop playing the last role it plays, if any.
@@ -55,12 +62,7 @@ module Rolable
55
62
  end
56
63
 
57
64
  # The context a role is played within. This method must be overidden in every __role definition module.
58
- def context
59
- nil
60
- end
61
-
62
- # The role definition code also have private access to the extra args given in the context instantiation.
63
- def settings(*keys)
64
- context.send(:settings, *keys) if context
65
- end
65
+ # def context
66
+ # nil
67
+ # end
66
68
  end
@@ -1,3 +1,3 @@
1
1
  module Drsi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -38,7 +38,7 @@ describe 'RolePlayers' do
38
38
  end
39
39
 
40
40
  def check_role1_context_access
41
- role1.context == self
41
+ [!role1.respond_to?(:context), role1.private_methods.map(&:to_s).include?('context'), role1.send(:context) == self].uniq == [true]
42
42
  end
43
43
 
44
44
  def check_role1_settings_access
@@ -95,9 +95,8 @@ describe 'RolePlayers' do
95
95
  @player1.name.should eq('player1')
96
96
  @player2.should_not respond_to(:role1)
97
97
  @player2.should_not respond_to(:context)
98
- @player1.should_not respond_to(:settings)
99
- @player1.private_methods.map(&:to_s).should include('settings')
100
- @player1.send(:settings).should be_nil
98
+ @player2.should_not respond_to(:settings)
99
+ (@player2.private_methods.map(&:to_s) & ['role1', 'context', 'settings']).should be_empty
101
100
  end
102
101
 
103
102
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorenzo Tello
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec