surrounded 1.0.0 → 1.1.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.
- checksums.yaml +5 -5
- data/Changelog.md +11 -11
- data/LICENSE.txt +1 -1
- data/README.md +39 -9
- data/Rakefile +12 -5
- data/lib/surrounded/access_control.rb +19 -26
- data/lib/surrounded/context/forwarding.rb +10 -10
- data/lib/surrounded/context/initializing.rb +10 -7
- data/lib/surrounded/context/name_collision_detector.rb +17 -17
- data/lib/surrounded/context/negotiator.rb +13 -13
- data/lib/surrounded/context/role_builders.rb +8 -7
- data/lib/surrounded/context/role_map.rb +20 -13
- data/lib/surrounded/context/seclusion.rb +20 -0
- data/lib/surrounded/context/trigger_controls.rb +14 -16
- data/lib/surrounded/context.rb +64 -72
- data/lib/surrounded/east_oriented.rb +4 -4
- data/lib/surrounded/exceptions.rb +1 -1
- data/lib/surrounded/shortcuts.rb +15 -5
- data/lib/surrounded/version.rb +2 -2
- data/lib/surrounded.rb +7 -7
- data/surrounded.gemspec +21 -16
- data/test/{casting_role_player_test.rb → casting_test_helper.rb} +4 -3
- data/test/collection_role_players_test.rb +16 -16
- data/test/context_access_test.rb +31 -30
- data/test/context_forwarding_test.rb +30 -30
- data/test/context_reuse_test.rb +14 -14
- data/test/context_shortcuts_test.rb +38 -11
- data/test/east_oriented_triggers_test.rb +14 -13
- data/test/example_delegate_class_test.rb +8 -8
- data/test/example_proxy_test.rb +25 -23
- data/test/example_threaded_test.rb +13 -13
- data/test/example_wrapper_test.rb +7 -7
- data/test/initialization_test.rb +25 -26
- data/test/name_collisions_test.rb +48 -42
- data/test/non_surrounded_role_player_test.rb +8 -8
- data/test/override_methods_test.rb +9 -9
- data/test/role_context_method_test.rb +144 -98
- data/test/surrounded_context_test.rb +71 -62
- data/test/surrounded_test.rb +13 -15
- data/test/test_helper.rb +8 -5
- data/test/threaded_context_test.rb +70 -0
- metadata +9 -52
- data/.codeclimate.yml +0 -4
- data/.gitignore +0 -19
- data/.pullreview.yml +0 -4
- data/.simplecov +0 -3
- data/.travis.yml +0 -19
- data/Gemfile +0 -10
- data/examples/bottles.rb +0 -145
- data/examples/rails.rb +0 -57
data/examples/bottles.rb
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
require 'surrounded'
|
|
2
|
-
|
|
3
|
-
class Countdown
|
|
4
|
-
extend Surrounded::Context
|
|
5
|
-
|
|
6
|
-
initialize :singer, :number, :location
|
|
7
|
-
|
|
8
|
-
trigger :start do
|
|
9
|
-
singer.start
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
trigger :continue do
|
|
13
|
-
singer.continue
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
trigger :finish do
|
|
17
|
-
singer.announce_status
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
role :singer do
|
|
21
|
-
def start
|
|
22
|
-
announce_full_status
|
|
23
|
-
take_action
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def continue
|
|
27
|
-
announce_status
|
|
28
|
-
pause
|
|
29
|
-
start
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def announce_full_status
|
|
33
|
-
output %{#{location.status}, #{location.inventory}}.capitalize
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def announce_status
|
|
37
|
-
output %{#{location.status}}.capitalize
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def take_action
|
|
41
|
-
if location.empty?
|
|
42
|
-
output %{Go to the store and get some more}
|
|
43
|
-
next_part.finish
|
|
44
|
-
else
|
|
45
|
-
output %{#{location.subtraction}, pass it around}.capitalize
|
|
46
|
-
next_part.continue
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def pause
|
|
51
|
-
output ""
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def next_part
|
|
55
|
-
context.class.new(singer, number.pred, location)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
role :number, :wrap do
|
|
60
|
-
def name
|
|
61
|
-
self.zero? ? 'no more' : to_i
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def pronoun
|
|
65
|
-
self == 1 ? 'it' : 'one'
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def container
|
|
69
|
-
self == 1 ? 'bottle' : 'bottles'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def pred
|
|
73
|
-
self.zero? ? 99 : super
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
role :location do
|
|
78
|
-
def empty?
|
|
79
|
-
number.zero?
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def inventory
|
|
83
|
-
%{#{number.name} #{number.container} of beer}
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def status
|
|
87
|
-
%{#{inventory} #{placement} #{name}}
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def subtraction
|
|
91
|
-
%{take #{number.pronoun} #{removal_strategy}}
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
class Location
|
|
97
|
-
include Surrounded
|
|
98
|
-
|
|
99
|
-
def placement
|
|
100
|
-
'on'
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def removal_strategy
|
|
104
|
-
'off'
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def name
|
|
108
|
-
"the " + self.class.to_s.downcase
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
class Wall < Location
|
|
113
|
-
def removal_strategy
|
|
114
|
-
'down'
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
class Box < Location
|
|
119
|
-
def placement
|
|
120
|
-
'in'
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def removal_strategy
|
|
124
|
-
'out'
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
class Chorus
|
|
129
|
-
include Surrounded
|
|
130
|
-
def output(value)
|
|
131
|
-
STDOUT.puts(value)
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
class Sheet
|
|
136
|
-
include Surrounded
|
|
137
|
-
def output(value)
|
|
138
|
-
File.open('bottles.txt', 'a') do |f|
|
|
139
|
-
f.puts(value)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
Countdown.new(Chorus.new, 3, Wall.new).start
|
|
145
|
-
# Countdown.new(Sheet.new, 3, Box.new).start
|
data/examples/rails.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Here's an example of how you might use this in rails.
|
|
2
|
-
|
|
3
|
-
# First, be guarded against changes in third-party libraries
|
|
4
|
-
module Awareness
|
|
5
|
-
def self.included(base)
|
|
6
|
-
base.class_eval {
|
|
7
|
-
include Surrounded
|
|
8
|
-
include Casting::Client
|
|
9
|
-
delegate_missing_methods
|
|
10
|
-
}
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
class User
|
|
15
|
-
include Awareness
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class ApplicationController
|
|
19
|
-
include Awareness
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class SomeUseCase
|
|
23
|
-
extend Surrounded::Context
|
|
24
|
-
|
|
25
|
-
initialize(:admin, :other_user, :listener)
|
|
26
|
-
|
|
27
|
-
trigger :do_something do
|
|
28
|
-
admin.something
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
module Admin
|
|
32
|
-
def something
|
|
33
|
-
puts "Hello, #{other_user}"
|
|
34
|
-
listener.redirect_to('/')
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
class OtherUser < ::User
|
|
39
|
-
def special_feature
|
|
40
|
-
#....
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def apply_behavior_other_user(role, behavior, role_player)
|
|
45
|
-
role_player.becomes(behavior)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
class SomethingController < ApplicationController
|
|
50
|
-
def create
|
|
51
|
-
surround(current_user, User.last).do_something
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def surround(admin, other)
|
|
55
|
-
SomeUseCase.new(admin, other, self)
|
|
56
|
-
end
|
|
57
|
-
end
|