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.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/Changelog.md +11 -11
  3. data/LICENSE.txt +1 -1
  4. data/README.md +39 -9
  5. data/Rakefile +12 -5
  6. data/lib/surrounded/access_control.rb +19 -26
  7. data/lib/surrounded/context/forwarding.rb +10 -10
  8. data/lib/surrounded/context/initializing.rb +10 -7
  9. data/lib/surrounded/context/name_collision_detector.rb +17 -17
  10. data/lib/surrounded/context/negotiator.rb +13 -13
  11. data/lib/surrounded/context/role_builders.rb +8 -7
  12. data/lib/surrounded/context/role_map.rb +20 -13
  13. data/lib/surrounded/context/seclusion.rb +20 -0
  14. data/lib/surrounded/context/trigger_controls.rb +14 -16
  15. data/lib/surrounded/context.rb +64 -72
  16. data/lib/surrounded/east_oriented.rb +4 -4
  17. data/lib/surrounded/exceptions.rb +1 -1
  18. data/lib/surrounded/shortcuts.rb +15 -5
  19. data/lib/surrounded/version.rb +2 -2
  20. data/lib/surrounded.rb +7 -7
  21. data/surrounded.gemspec +21 -16
  22. data/test/{casting_role_player_test.rb → casting_test_helper.rb} +4 -3
  23. data/test/collection_role_players_test.rb +16 -16
  24. data/test/context_access_test.rb +31 -30
  25. data/test/context_forwarding_test.rb +30 -30
  26. data/test/context_reuse_test.rb +14 -14
  27. data/test/context_shortcuts_test.rb +38 -11
  28. data/test/east_oriented_triggers_test.rb +14 -13
  29. data/test/example_delegate_class_test.rb +8 -8
  30. data/test/example_proxy_test.rb +25 -23
  31. data/test/example_threaded_test.rb +13 -13
  32. data/test/example_wrapper_test.rb +7 -7
  33. data/test/initialization_test.rb +25 -26
  34. data/test/name_collisions_test.rb +48 -42
  35. data/test/non_surrounded_role_player_test.rb +8 -8
  36. data/test/override_methods_test.rb +9 -9
  37. data/test/role_context_method_test.rb +144 -98
  38. data/test/surrounded_context_test.rb +71 -62
  39. data/test/surrounded_test.rb +13 -15
  40. data/test/test_helper.rb +8 -5
  41. data/test/threaded_context_test.rb +70 -0
  42. metadata +9 -52
  43. data/.codeclimate.yml +0 -4
  44. data/.gitignore +0 -19
  45. data/.pullreview.yml +0 -4
  46. data/.simplecov +0 -3
  47. data/.travis.yml +0 -19
  48. data/Gemfile +0 -10
  49. data/examples/bottles.rb +0 -145
  50. 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