surrounded 1.1.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 +4 -4
  2. data/Changelog.md +11 -20
  3. data/LICENSE.txt +1 -1
  4. data/README.md +3 -3
  5. data/Rakefile +12 -5
  6. data/lib/surrounded/access_control.rb +12 -11
  7. data/lib/surrounded/context/forwarding.rb +10 -10
  8. data/lib/surrounded/context/initializing.rb +8 -6
  9. data/lib/surrounded/context/name_collision_detector.rb +17 -17
  10. data/lib/surrounded/context/negotiator.rb +7 -8
  11. data/lib/surrounded/context/role_builders.rb +7 -7
  12. data/lib/surrounded/context/role_map.rb +6 -8
  13. data/lib/surrounded/context/trigger_controls.rb +11 -13
  14. data/lib/surrounded/context.rb +61 -56
  15. data/lib/surrounded/east_oriented.rb +4 -4
  16. data/lib/surrounded/exceptions.rb +1 -1
  17. data/lib/surrounded/shortcuts.rb +6 -8
  18. data/lib/surrounded/version.rb +1 -1
  19. data/lib/surrounded.rb +7 -7
  20. data/surrounded.gemspec +21 -15
  21. data/test/{casting_role_player_test.rb → casting_test_helper.rb} +4 -3
  22. data/test/collection_role_players_test.rb +16 -16
  23. data/test/context_access_test.rb +31 -30
  24. data/test/context_forwarding_test.rb +30 -30
  25. data/test/context_reuse_test.rb +14 -14
  26. data/test/context_shortcuts_test.rb +18 -16
  27. data/test/east_oriented_triggers_test.rb +14 -13
  28. data/test/example_delegate_class_test.rb +8 -8
  29. data/test/example_proxy_test.rb +25 -23
  30. data/test/example_threaded_test.rb +13 -13
  31. data/test/example_wrapper_test.rb +7 -7
  32. data/test/initialization_test.rb +24 -25
  33. data/test/name_collisions_test.rb +48 -42
  34. data/test/non_surrounded_role_player_test.rb +8 -8
  35. data/test/override_methods_test.rb +9 -9
  36. data/test/role_context_method_test.rb +129 -119
  37. data/test/surrounded_context_test.rb +71 -62
  38. data/test/surrounded_test.rb +13 -15
  39. data/test/test_helper.rb +5 -4
  40. data/test/threaded_context_test.rb +70 -0
  41. metadata +8 -38
  42. data/.codeclimate.yml +0 -4
  43. data/.github/workflows/codeql-analysis.yml +0 -70
  44. data/.github/workflows/test.yml +0 -18
  45. data/.gitignore +0 -19
  46. data/.pullreview.yml +0 -4
  47. data/.simplecov +0 -3
  48. data/Gemfile +0 -9
  49. data/examples/bottles.rb +0 -135
  50. data/examples/rails.rb +0 -57
data/examples/bottles.rb DELETED
@@ -1,135 +0,0 @@
1
- require "surrounded"
2
- class CountdownSong
3
- def initialize(max:, min:)
4
- @max = max
5
- @min = min
6
- end
7
- attr_reader :max, :min
8
-
9
- def sing_with(verse_template)
10
- max.downto(min).map { |num| verse(num, verse_template) }
11
- end
12
-
13
- def verse(number, verse_template)
14
- verse_template.lyrics(number)
15
- end
16
- end
17
-
18
- class BottleVerse
19
- def self.lyrics(number)
20
- new(bottle_number: number).lyrics
21
- end
22
-
23
- extend Surrounded::Context
24
-
25
- initialize :bottle_number
26
-
27
- trigger :lyrics do
28
- "#{bottle_number} of beer on the wall, ".capitalize +
29
- "#{bottle_number} of beer.\n" +
30
- "#{bottle_number.action}, " +
31
- "#{bottle_number.successor} of beer on the wall.\n"
32
- end
33
-
34
- role :bottle_number, :wrapper do
35
- def self.handles(number)
36
- BottleVerse.register_bottle_role(number, self)
37
- end
38
-
39
- def to_s
40
- "#{quantity} #{container}"
41
- end
42
-
43
- def quantity
44
- __getobj__.to_s
45
- end
46
-
47
- def container
48
- "bottles"
49
- end
50
-
51
- def action
52
- "Take #{pronoun} down and pass it around"
53
- end
54
-
55
- def pronoun
56
- "one"
57
- end
58
-
59
- def successor
60
- context.bottle_role_player(pred)
61
- end
62
- end
63
-
64
- # Inherit from existing role
65
- def self.bottle_role(name, &block)
66
- mod_name = RoleName(name)
67
- klass = Class.new(BottleNumber, &block)
68
- const_set(mod_name, klass)
69
- end
70
-
71
- def self.register_bottle_role(number, klass)
72
- @@registry ||= Hash.new { BottleNumber }
73
- @@registry[number] = klass
74
- end
75
-
76
- def bottle_role_for(number)
77
- @@registry[number]
78
- end
79
-
80
- def map_role_bottle_number(num)
81
- map_role(:bottle_number, bottle_role_for(num), num)
82
- end
83
-
84
- def bottle_role_player(number)
85
- bottle_role_for(number).new(number)
86
- end
87
-
88
- role :bottle_number_0, :bottle_role do
89
- handles 0
90
-
91
- def quantity
92
- "no more"
93
- end
94
-
95
- def action
96
- "Go to the store and buy some more"
97
- end
98
-
99
- def successor
100
- context.bottle_role_player(99)
101
- end
102
- end
103
-
104
- role :bottle_number_1, :bottle_role do
105
- handles 1
106
-
107
- def container
108
- "bottle"
109
- end
110
-
111
- def pronoun
112
- "it"
113
- end
114
- end
115
- end
116
-
117
- class Bottles
118
- def song_template(upper: 99, lower: 0)
119
- CountdownSong.new(max: upper, min: lower)
120
- end
121
-
122
- def song
123
- song_template.sing_with(BottleVerse)
124
- end
125
-
126
- def verses(upper, lower)
127
- song_template(upper: upper, lower: lower).sing_with(BottleVerse)
128
- end
129
-
130
- def verse(number)
131
- song_template.verse(number, BottleVerse)
132
- end
133
- end
134
-
135
- puts Bottles.new.song
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