puremvc 1.0.0 → 1.0.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 (51) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +11 -0
  3. data/LICENSE +28 -0
  4. data/README.md +88 -0
  5. data/lib/core/controller.rb +177 -0
  6. data/lib/core/model.rb +133 -0
  7. data/lib/core/view.rb +230 -0
  8. data/lib/patterns/command/macro_command.rb +81 -0
  9. data/lib/patterns/command/simple_command.rb +28 -0
  10. data/lib/patterns/facade/facade.rb +267 -0
  11. data/lib/patterns/mediator/mediator.rb +56 -0
  12. data/lib/patterns/observer/notification.rb +68 -0
  13. data/lib/patterns/observer/notifier.rb +87 -0
  14. data/lib/patterns/observer/observer.rb +55 -0
  15. data/lib/patterns/proxy/proxy.rb +50 -0
  16. data/lib/puremvc.rb +19 -0
  17. data/sig/lib/core/controller.rbs +40 -0
  18. data/sig/lib/core/model.rbs +38 -0
  19. data/sig/lib/core/view.rbs +42 -0
  20. data/sig/lib/interfaces/i_command.rbs +18 -0
  21. data/sig/lib/interfaces/i_controller.rbs +52 -0
  22. data/sig/lib/interfaces/i_facade.rbs +116 -0
  23. data/sig/lib/interfaces/i_mediator.rbs +60 -0
  24. data/sig/lib/interfaces/i_model.rbs +38 -0
  25. data/sig/lib/interfaces/i_notification.rbs +52 -0
  26. data/sig/lib/interfaces/i_notifier.rbs +48 -0
  27. data/sig/lib/interfaces/i_observer.rbs +56 -0
  28. data/sig/lib/interfaces/i_proxy.rbs +36 -0
  29. data/sig/lib/interfaces/i_view.rbs +71 -0
  30. data/sig/lib/patterns/command/macro_command.rbs +18 -0
  31. data/sig/lib/patterns/command/simple_command.rbs +11 -0
  32. data/sig/lib/patterns/facade/facade.rbs +48 -0
  33. data/sig/lib/patterns/mediator/mediator.rbs +18 -0
  34. data/sig/lib/patterns/observer/notification.rbs +18 -0
  35. data/sig/lib/patterns/observer/notifier.rbs +17 -0
  36. data/sig/lib/patterns/observer/observer.rbs +20 -0
  37. data/sig/lib/patterns/proxy/proxy.rbs +19 -0
  38. metadata +71 -56
  39. data/puremvc.rb +0 -13
  40. data/src/org/puremvc/ruby/core/controller.rb +0 -76
  41. data/src/org/puremvc/ruby/core/model.rb +0 -57
  42. data/src/org/puremvc/ruby/core/view.rb +0 -112
  43. data/src/org/puremvc/ruby/patterns/command/macro_command.rb +0 -59
  44. data/src/org/puremvc/ruby/patterns/command/simple_command.rb +0 -17
  45. data/src/org/puremvc/ruby/patterns/facade/facade.rb +0 -161
  46. data/src/org/puremvc/ruby/patterns/mediator/mediator.rb +0 -37
  47. data/src/org/puremvc/ruby/patterns/observer/notification.rb +0 -38
  48. data/src/org/puremvc/ruby/patterns/observer/notifier.rb +0 -27
  49. data/src/org/puremvc/ruby/patterns/observer/observer.rb +0 -31
  50. data/src/org/puremvc/ruby/patterns/proxy/proxy.rb +0 -32
  51. data/version.txt +0 -12
@@ -0,0 +1,71 @@
1
+ module PureMVC
2
+ # The interface definition for a PureMVC View.
3
+ #
4
+ # In PureMVC, <code>_IView</code> implementors assume these responsibilities:
5
+ #
6
+ # In PureMVC, the <code>View</code> class assumes these responsibilities:
7
+ # - Maintain a cache of <code>_IMediator</code> instances.
8
+ # - Provide methods for registering, retrieving, and removing <code>_IMediators</code>.
9
+ # - Managing the observer lists for each <code>_INotification</code> in the application.
10
+ # - Providing a method for attaching <code>_IObservers</code> to an <code>_INotification</code>'s observer list.
11
+ # - Providing a method for broadcasting an <code>_INotification</code>.
12
+ # - Notifying the <code>_IObservers</code> of a given <code>_INotification</code> when it is broadcast.
13
+ interface _IView
14
+ # Register an <code>_IObserver</code> to be notified of <code>_INotifications</code> with a given name.
15
+ #
16
+ # @param notification_name [String] the name of the <code>_INotifications</code> to notify this <code>_IObserver</code> of
17
+ # @param observer [_IObserver] the <code>_IObserver</code> to register
18
+ def register_observer: (String notification_name, _IObserver observer) -> void
19
+
20
+ # Notify the <code>_IObservers</code> for a particular <code>_INotification</code>.
21
+ #
22
+ # All previously attached <code>_IObservers</code> for this <code>_INotification</code>'s
23
+ # list are notified and are passed a reference to the <code>_INotification</code> in
24
+ # the order in which they were registered.
25
+ #
26
+ # @param notification [_INotification] the <code>_INotification</code> to notify <code>_IObservers</code> of.
27
+ def notify_observers: (_INotification notification) -> void
28
+
29
+ # Remove a group of observers from the observer list for a given <code>Notification</code> name.
30
+ #
31
+ # @param notification_name [String] which observer list to remove from
32
+ # @param notify_context [untyped] remove the observers with this object as their notifyContext
33
+ def remove_observer: (String notification_name, untyped notify_context) -> void
34
+
35
+ # Register an <code>_IMediator</code> instance with the <code>View</code>.
36
+ #
37
+ # Registers the <code>_IMediator</code> so that it can be retrieved by name,
38
+ # and further interrogates the <code>_IMediator</code> for its
39
+ # <code>_INotification</code> interests.
40
+ #
41
+ # If the <code>_IMediator</code> returns any <code>_INotification</code>
42
+ # names to be notified about, an <code>Observer</code> is created encapsulating
43
+ # the <code>_IMediator</code> instance's <code>handleNotification</code> method
44
+ # and registering it as an <code>Observer</code> for all <code>_INotifications</code> the
45
+ # <code>_IMediator</code> is interested in.
46
+ #
47
+ # @param mediator [_IMediator] a reference to the <code>_IMediator</code> instance
48
+ def register_mediator: (_IMediator mediator) -> void
49
+
50
+ # Retrieve an <code>_IMediator</code> from the <code>View</code>.
51
+ #
52
+ # @param mediator_name [String] the name of the <code>_IMediator</code> instance to retrieve.
53
+ # @return [_IMediator | nil] the <code>_IMediator</code> instance previously registered with the given <code>mediatorName</code>.
54
+ def retrieve_mediator: (String mediator_name) -> _IMediator?
55
+
56
+ # Check if a <code>Mediator</code> is registered or not.
57
+ #
58
+ # @param mediator_name [String]
59
+ # @return [Boolean] whether a <code>Mediator</code> is registered with the given <code>mediatorName</code>.
60
+ def has_mediator?: (String mediator_name) -> bool
61
+
62
+ # Remove an <code>_IMediator</code> from the <code>View</code>.
63
+ #
64
+ # @param mediator_name [String] name of the <code>_IMediator</code> instance to be removed.
65
+ # @return [_IMediator] the <code>_IMediator</code> that was removed from the <code>View</code>
66
+ def remove_mediator: (String mediator_name) -> _IMediator?
67
+ end
68
+
69
+ # Assert that the given `View` type parameter is a subtype of `_IView`
70
+ type validate_view[View < _IView] = top
71
+ end
@@ -0,0 +1,18 @@
1
+ module PureMVC
2
+
3
+ class MacroCommand < Notifier
4
+
5
+ include _ICommand
6
+
7
+ @sub_commands: Array[^() -> _ICommand]
8
+
9
+ def initialize: () -> void
10
+
11
+ def initialize_macro_command: () -> void
12
+
13
+ def add_sub_command: () { () -> _ICommand } -> void
14
+ end
15
+
16
+ # Type-level assertion that MacroCommand conforms to _ICommand
17
+ type macro_command_validation = validate_command[MacroCommand]
18
+ end
@@ -0,0 +1,11 @@
1
+ module PureMVC
2
+
3
+ class SimpleCommand < Notifier
4
+
5
+ include _ICommand
6
+
7
+ end
8
+
9
+ # Type-level assertion that SimpleCommand conforms to _ICommand
10
+ type simple_command_validation = validate_command[SimpleCommand]
11
+ end
@@ -0,0 +1,48 @@
1
+ module PureMVC
2
+
3
+ class Facade
4
+
5
+ include _IFacade
6
+
7
+ self.@instance_map: Hash[String, _IFacade]
8
+
9
+ self.@mutex: Mutex
10
+
11
+ @model: _IModel?
12
+
13
+ @controller: _IController?
14
+
15
+ @view: _IView?
16
+
17
+ @multiton_key: String
18
+
19
+ MULTITON_MSG: String
20
+
21
+ def self.instance_map: () -> Hash[String, _IFacade]
22
+
23
+ private
24
+
25
+ def self.mutex: () -> Mutex
26
+
27
+ public
28
+
29
+ def self.get_instance: (String key) { (String k) -> _IFacade } -> _IFacade
30
+
31
+ def self.has_core?: (String key) -> bool
32
+
33
+ def self.remove_core: (String key) -> void
34
+
35
+ def initialize: (String key) -> void
36
+
37
+ def initialize_facade: () -> void
38
+
39
+ def initialize_controller: () -> void
40
+
41
+ def initialize_model: () -> void
42
+
43
+ def initialize_view: () -> void
44
+ end
45
+
46
+ # Type-level assertion that Facade conforms to _IFacade
47
+ type facade_validation = validate_facade[Facade]
48
+ end
@@ -0,0 +1,18 @@
1
+ module PureMVC
2
+
3
+ class Mediator < Notifier
4
+
5
+ include _IMediator
6
+
7
+ NAME: String
8
+
9
+ attr_reader name: String
10
+
11
+ attr_accessor component: Object?
12
+
13
+ def initialize: (?String? name, ?Object? component) -> void
14
+ end
15
+
16
+ # Type-level assertion that Mediator conforms to _IMediator
17
+ type mediator_validation = validate_mediator[Mediator]
18
+ end
@@ -0,0 +1,18 @@
1
+ module PureMVC
2
+
3
+ class Notification
4
+
5
+ include _INotification
6
+
7
+ attr_reader name: String
8
+
9
+ attr_accessor body: Object?
10
+
11
+ attr_accessor type: String?
12
+
13
+ def initialize: (String name, ?Object? body, ?String? type) -> void
14
+ end
15
+
16
+ # Type-level assertion that Notification conforms to _INotification
17
+ type notification_validation = validate_notification[Notification]
18
+ end
@@ -0,0 +1,17 @@
1
+ module PureMVC
2
+
3
+ class Notifier
4
+
5
+ include _INotifier
6
+
7
+ @multiton_key: String
8
+
9
+ MULTITON_MSG: String
10
+
11
+ def multiton_key: () -> String
12
+
13
+ end
14
+
15
+ # Type-level assertion that Notifier conforms to _INotifier
16
+ type notifier_validation = validate_notifier[Notifier]
17
+ end
@@ -0,0 +1,20 @@
1
+ module PureMVC
2
+
3
+ class Observer
4
+
5
+ include _IObserver
6
+
7
+ attr_accessor notify: Method?
8
+
9
+ attr_accessor context: Object?
10
+
11
+ def initialize: (?Method? notify, ?Object? context) -> void
12
+
13
+ def notify_observer: (_INotification) -> void
14
+
15
+ def compare_notify_context?: (Object) -> bool
16
+ end
17
+
18
+ # Type-level assertion that Observer conforms to _IObserver
19
+ type observer_validation = validate_observer[Observer]
20
+ end
@@ -0,0 +1,19 @@
1
+ module PureMVC
2
+
3
+ class Proxy < Notifier
4
+
5
+ include _IProxy
6
+
7
+ NAME: String
8
+
9
+ attr_reader name: String
10
+
11
+ attr_accessor data: Object?
12
+
13
+ def initialize: (?String? name, ?Object? data) -> void
14
+ end
15
+
16
+ # Type-level assertion that Proxy conforms to _IProxy
17
+ type proxy_validation = validate_proxy[Proxy]
18
+ end
19
+
metadata CHANGED
@@ -1,68 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: puremvc
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
6
5
  platform: ruby
7
- authors:
8
- - Jake Dempsey
9
- autorequire:
6
+ authors:
7
+ - Saad Shams
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-07-27 00:00:00 -03:00
14
- default_executable:
11
+ date: 2025-08-14 00:00:00.000000000 Z
15
12
  dependencies: []
16
-
17
- description: PureMVC is a lightweight framework for creating applications based upon the classic Model-View-Controller design meta-pattern. This is the specific implementation for the Ruby language based on the Standard Version AS3 reference.
18
- email: jake.dempsey@puremvc.org
13
+ description: PureMVC is a lightweight framework for Model-View-Controller app development.
14
+ email:
15
+ - saad.shams@puremvc.org
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
- extra_rdoc_files:
24
- - version.txt
25
- files:
26
- - src/org/puremvc/ruby/core/controller.rb
27
- - src/org/puremvc/ruby/core/model.rb
28
- - src/org/puremvc/ruby/core/view.rb
29
- - src/org/puremvc/ruby/patterns/command/macro_command.rb
30
- - src/org/puremvc/ruby/patterns/command/simple_command.rb
31
- - src/org/puremvc/ruby/patterns/facade/facade.rb
32
- - src/org/puremvc/ruby/patterns/mediator/mediator.rb
33
- - src/org/puremvc/ruby/patterns/observer/notification.rb
34
- - src/org/puremvc/ruby/patterns/observer/notifier.rb
35
- - src/org/puremvc/ruby/patterns/observer/observer.rb
36
- - src/org/puremvc/ruby/patterns/proxy/proxy.rb
37
- - puremvc.rb
38
- - version.txt
39
- has_rdoc: true
40
- homepage: http://trac.puremvc.org/PureMVC_Ruby/
41
- licenses: []
42
-
43
- post_install_message:
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE
22
+ - README.md
23
+ - lib/core/controller.rb
24
+ - lib/core/model.rb
25
+ - lib/core/view.rb
26
+ - lib/patterns/command/macro_command.rb
27
+ - lib/patterns/command/simple_command.rb
28
+ - lib/patterns/facade/facade.rb
29
+ - lib/patterns/mediator/mediator.rb
30
+ - lib/patterns/observer/notification.rb
31
+ - lib/patterns/observer/notifier.rb
32
+ - lib/patterns/observer/observer.rb
33
+ - lib/patterns/proxy/proxy.rb
34
+ - lib/puremvc.rb
35
+ - sig/lib/core/controller.rbs
36
+ - sig/lib/core/model.rbs
37
+ - sig/lib/core/view.rbs
38
+ - sig/lib/interfaces/i_command.rbs
39
+ - sig/lib/interfaces/i_controller.rbs
40
+ - sig/lib/interfaces/i_facade.rbs
41
+ - sig/lib/interfaces/i_mediator.rbs
42
+ - sig/lib/interfaces/i_model.rbs
43
+ - sig/lib/interfaces/i_notification.rbs
44
+ - sig/lib/interfaces/i_notifier.rbs
45
+ - sig/lib/interfaces/i_observer.rbs
46
+ - sig/lib/interfaces/i_proxy.rbs
47
+ - sig/lib/interfaces/i_view.rbs
48
+ - sig/lib/patterns/command/macro_command.rbs
49
+ - sig/lib/patterns/command/simple_command.rbs
50
+ - sig/lib/patterns/facade/facade.rbs
51
+ - sig/lib/patterns/mediator/mediator.rbs
52
+ - sig/lib/patterns/observer/notification.rbs
53
+ - sig/lib/patterns/observer/notifier.rbs
54
+ - sig/lib/patterns/observer/observer.rbs
55
+ - sig/lib/patterns/proxy/proxy.rbs
56
+ homepage: https://github.com/puremvc/puremvc-ruby-multicore-framework
57
+ licenses:
58
+ - BSD-3-Clause
59
+ metadata:
60
+ steep_types: sig
61
+ github_repo: https://github.com/puremvc/puremvc-ruby-multicore-framework
62
+ source_code_uri: https://github.com/puremvc/puremvc-ruby-multicore-framework
63
+ bug_tracker_uri: https://github.com/puremvc/puremvc-ruby-multicore-framework/issues
64
+ post_install_message:
44
65
  rdoc_options: []
45
-
46
- require_paths:
47
- - .
48
- required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
51
70
  - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
71
+ - !ruby/object:Gem::Version
72
+ version: '3.0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
57
75
  - - ">="
58
- - !ruby/object:Gem::Version
59
- version: "0"
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
60
78
  requirements: []
61
-
62
- rubyforge_project:
63
- rubygems_version: 1.6.2
64
- signing_key:
65
- specification_version: 3
66
- summary: Lightweight Framework for applications based upon the classic Model-View-Controller design meta-pattern.
79
+ rubygems_version: 3.4.10
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: PureMVC Multicore Framework
67
83
  test_files: []
68
-
data/puremvc.rb DELETED
@@ -1,13 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), 'src/org/puremvc/ruby')
2
- require 'singleton'
3
- require 'patterns/facade/facade'
4
- require 'patterns/proxy/proxy'
5
- require 'patterns/observer/observer'
6
- require 'patterns/observer/notification'
7
- require 'patterns/observer/notifier'
8
- require 'patterns/mediator/mediator'
9
- require 'patterns/command/macro_command'
10
- require 'patterns/command/simple_command'
11
- require 'core/controller'
12
- require 'core/model'
13
- require 'core/view'
@@ -1,76 +0,0 @@
1
- # In PureMVC, the Controller class assumes these responsibilities:
2
- # * Remembering which Command is intended to handle which Notification.
3
- # * Registering itself as an Observer with the View for each Notification that it has an Command mapping for.
4
- # * Creating instances of the proper Command to handle a given Notification when notified by the View.
5
- # * Calling the Command's execute method, passing in the Notification.
6
- #
7
- # Your application must register any Commands with the Controller.
8
- #
9
- # The simplest way is to subclass Facade, and use its initializeController method to add your registrations.
10
- #
11
- # * Command refers to SimpleCommand or MacroCommand
12
-
13
-
14
- class Controller
15
- attr_accessor :command_map, :view
16
-
17
- include Singleton
18
-
19
- # This Controller implementation is a Singleton,
20
- # so you can not call the constructor
21
- # directly, but instead call the static Singleton
22
- # Factory method Controller.instance
23
- def initialize
24
- @command_map = {}
25
- initialize_controller
26
- end
27
-
28
- # Initialize the Singleton Controller instance.
29
- #
30
- # Called Automatically by the construcor.
31
- #
32
- # Note that if you are using a subclass of View in your application, you should also
33
- # subclass Controller and override the initialize_controller method in the following way:
34
- #
35
- # <tt>
36
- # def initialize_controller
37
- # @view = MyView.instance
38
- # end
39
- # </tt>
40
- def initialize_controller
41
- @view = View.instance
42
- end
43
-
44
- # If a Command has previously been registered to handle a given Notification, then it is executed
45
- def execute_command(notification)
46
- return unless @command_map[notification.name]
47
- @command_map[notification.name].new().execute(notification)
48
- end
49
-
50
-
51
- # Register a particular Command class as the handler for a particular Notification.
52
- #
53
- # If a Command has already been registered to handle Notification's with this name, it is
54
- # no longer user, the new Command is used instead.
55
- #
56
- # The Observer for the new Command is only created if this is the first time a Command
57
- # has been registered for this Notification name.
58
- def register_command(notification_name, command_class)
59
- @view.register_observer( notification_name, Observer.new(:execute_command, self) );
60
- @command_map[notification_name] = command_class
61
- end
62
-
63
- # Check if a command is registered for a given Notification
64
- def has_command?(notification_name)
65
- !@command_map[notification_name].nil?
66
- end
67
-
68
- # Remove a previously registered Command for a given Notification
69
- def remove_command(notification_name)
70
- @view.remove_observer(notification_name, self)
71
- @command_map.delete(notification_name)
72
- end
73
- end
74
- # PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
75
- # PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
76
- # Your reuse is governed by the Creative Commons Attribution 3.0 License
@@ -1,57 +0,0 @@
1
- # In PureMVC, the Model class provides access to model objects (Proxies) by named lookup.
2
- #
3
- # The Model assumes these responsibilities:
4
- # * Maintain a cache of Proxy instances.
5
- # * Provide methods for registering, retrieving, and removing Proxy instances.
6
- #
7
- # Your application must register Proxy instances with the Model.
8
- # Typically, you use an Command to create and register Proxy
9
- # instances once the Facade has initialized the Core actors.
10
-
11
- class Model
12
-
13
- include Singleton
14
- attr_accessor :proxy_map
15
-
16
-
17
- # This Model implementation is a Singleton, so you can not call the constructor
18
- # directly, but instead call the static Singleton Factory method Model.instance
19
- def initialize
20
- @proxy_map = {}
21
- initialize_model
22
- end
23
-
24
-
25
- # Initialize the Singleton Model instance.
26
- #
27
- # Called automatically by the constructor, this is your opportunity to initialize the Singleton
28
- # instance in your subclass without overriding the constructor.
29
- def initialize_model
30
- end
31
-
32
- # Register a Proxy with the Model.
33
- def register_proxy(proxy)
34
- @proxy_map[proxy.name] = proxy
35
- proxy.on_register
36
- end
37
-
38
- # Retrieve a Proxy from the Model
39
- def retrieve_proxy(proxy_name)
40
- @proxy_map[proxy_name]
41
- end
42
-
43
- # Check if a Proxy is registered.
44
- def has_proxy?(proxy_name)
45
- !@proxy_map[proxy_name].nil?
46
- end
47
-
48
- # Remove a Proxy from teh Model.
49
- def remove_proxy(proxy_name)
50
- proxy = @proxy_map.delete(proxy_name)
51
- proxy.on_remove
52
- proxy
53
- end
54
- end
55
- # PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
56
- # PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
57
- # Your reuse is governed by the Creative Commons Attribution 3.0 License
@@ -1,112 +0,0 @@
1
- # In PureMVC, the View class assumes these responsibilities:
2
- #
3
- # * Maintain a cache of IMediator instances.
4
- # * Provide methods for registering, retrieving, and removing Mediators.
5
- # * Notifiying Mediators when they are registered or removed.
6
- # * Managing the observer lists for each Notification in the application.
7
- # * Providing a method for attaching Observers to an Notification's observer list.
8
- # * Providing a method for broadcasting an Notification.
9
- # * Notifying the Observers of a given Notification when it broadcast.
10
- class View
11
- include Singleton
12
-
13
- attr_accessor :mediator_map, :observer_map
14
-
15
-
16
- # This View implementation is a Singleton, so you should not call the constructor
17
- # directly, but instead call the static Singleton Factory method View.instance.
18
- def initialize
19
- @mediator_map = {}
20
- @observer_map = {}
21
- initialize_view
22
- end
23
-
24
- # Initialize the Singleton View instance.
25
- #
26
- # Called automatically by the constructor, this is your opportunity to initialize
27
- # the Singleton instance in your subclass without overriding the constructor
28
- def initialize_view
29
- end
30
-
31
- # Register an Observer to be notified of Notifications with a given name.
32
- def register_observer(notification_name, observer)
33
- observers = @observer_map[notification_name]
34
- if observers.nil?
35
- @observer_map[notification_name] = observer
36
- else
37
- observers = Array(@observer_map[notification_name])
38
- observers << observer
39
- @observer_map[notification_name] = observers
40
- end
41
- end
42
-
43
- # Notify the Observers for a particular Notification.
44
- #
45
- # All previously attached Observers for this Notification's list are notified
46
- # and are passed a reference to the Notification in the order in which they were registered.
47
- def notify_observers(notification)
48
- observers = Array(@observer_map[notification.name])
49
- observers.each{|observer| observer.notify_observer(notification)}
50
- end
51
-
52
- # Remove the observer for a given notify context from an observer list for a given
53
- # Notification name.
54
- def remove_observer(notification_name, observer)
55
- observers = @observer_map[notification_name]
56
- observers = [observers] unless observers.is_a?(Array)
57
- @observer_map[notification_name] = observers.reject { |o| o.compare_notify_context(observer) }
58
- @observer_map.delete(notification_name) if observers.size.zero?
59
- end
60
-
61
- # Register a Mediator instance with the View.
62
- #
63
- # Registers the Mediator so that it can be retrieved by name and further interrogates
64
- # the mediator for its Notification interests.
65
- #
66
- # If the mediator returns any Notifiation name to be notified about, an Observer is created
67
- # encapsulating the Mediator instance's handle_notification method and registering it as an
68
- # Observer for all Notifications the Mediator is interested in.
69
- def register_mediator(mediator)
70
- unless @mediator_map[mediator.name]
71
- @mediator_map[mediator.name] = mediator
72
- observer = Observer.new(:handle_notification, mediator)
73
- mediator.list_notification_interests.each do |interest|
74
- register_observer(interest, observer)
75
- end
76
- mediator.on_register
77
- end
78
- end
79
-
80
- # Retrieve a mediator from the View.
81
- #
82
- # returns the previously registered Mediator with the given name.
83
- def retrieve_mediator(mediator_name)
84
- @mediator_map[mediator_name]
85
- end
86
-
87
- # Remove a Mediator from the View.
88
- #
89
- # returns the Mediator that was removed.
90
- def remove_mediator(mediator_name)
91
- mediator = @mediator_map[mediator_name]
92
- if mediator
93
- mediator.list_notification_interests.each do |interest|
94
- remove_observer(interest, mediator)
95
- end
96
- @mediator_map.delete(mediator_name)
97
- mediator.on_remove
98
- end
99
- mediator
100
- end
101
-
102
- # Check if a Mediator is registered or not.
103
- #
104
- # returns whether a Mediator is registered with the given name.
105
- def has_mediator?(mediator_name)
106
- !@mediator_map[mediator_name].nil?
107
- end
108
-
109
- end
110
- # PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
111
- # PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
112
- # Your reuse is governed by the Creative Commons Attribution 3.0 License