puremvc 1.0.0 → 1.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 +7 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE +28 -0
- data/README.md +88 -0
- data/sig/core/controller.rbs +40 -0
- data/sig/core/model.rbs +38 -0
- data/sig/core/view.rbs +42 -0
- data/sig/interfaces/i_command.rbs +18 -0
- data/sig/interfaces/i_controller.rbs +52 -0
- data/sig/interfaces/i_facade.rbs +116 -0
- data/sig/interfaces/i_mediator.rbs +60 -0
- data/sig/interfaces/i_model.rbs +38 -0
- data/sig/interfaces/i_notification.rbs +52 -0
- data/sig/interfaces/i_notifier.rbs +48 -0
- data/sig/interfaces/i_observer.rbs +56 -0
- data/sig/interfaces/i_proxy.rbs +36 -0
- data/sig/interfaces/i_view.rbs +71 -0
- data/sig/patterns/command/macro_command.rbs +18 -0
- data/sig/patterns/command/simple_command.rbs +11 -0
- data/sig/patterns/facade/facade.rbs +48 -0
- data/sig/patterns/mediator/mediator.rbs +18 -0
- data/sig/patterns/observer/notification.rbs +18 -0
- data/sig/patterns/observer/notifier.rbs +17 -0
- data/sig/patterns/observer/observer.rbs +20 -0
- data/sig/patterns/proxy/proxy.rbs +19 -0
- data/src/core/controller.rb +177 -0
- data/src/core/model.rb +133 -0
- data/src/core/view.rb +230 -0
- data/src/patterns/command/macro_command.rb +81 -0
- data/src/patterns/command/simple_command.rb +28 -0
- data/src/patterns/facade/facade.rb +267 -0
- data/src/patterns/mediator/mediator.rb +56 -0
- data/src/patterns/observer/notification.rb +68 -0
- data/src/patterns/observer/notifier.rb +87 -0
- data/src/patterns/observer/observer.rb +55 -0
- data/src/patterns/proxy/proxy.rb +50 -0
- data/src/puremvc.rb +19 -0
- metadata +71 -56
- data/puremvc.rb +0 -13
- data/src/org/puremvc/ruby/core/controller.rb +0 -76
- data/src/org/puremvc/ruby/core/model.rb +0 -57
- data/src/org/puremvc/ruby/core/view.rb +0 -112
- data/src/org/puremvc/ruby/patterns/command/macro_command.rb +0 -59
- data/src/org/puremvc/ruby/patterns/command/simple_command.rb +0 -17
- data/src/org/puremvc/ruby/patterns/facade/facade.rb +0 -161
- data/src/org/puremvc/ruby/patterns/mediator/mediator.rb +0 -37
- data/src/org/puremvc/ruby/patterns/observer/notification.rb +0 -38
- data/src/org/puremvc/ruby/patterns/observer/notifier.rb +0 -27
- data/src/org/puremvc/ruby/patterns/observer/observer.rb +0 -31
- data/src/org/puremvc/ruby/patterns/proxy/proxy.rb +0 -32
- data/version.txt +0 -12
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# notification.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
module PureMVC
|
10
|
+
# A base <code>INotification</code>implementation.
|
11
|
+
#
|
12
|
+
# PureMVC does not rely upon underlying event models such
|
13
|
+
# as the one provided with Flash, and ActionScript 3 does
|
14
|
+
# not have an inherent event model.
|
15
|
+
#
|
16
|
+
# The Observer Pattern as implemented within PureMVC exists
|
17
|
+
# to support event-driven communication between the
|
18
|
+
# application and the actors of the MVC triad.
|
19
|
+
#
|
20
|
+
# Notifications are not meant to be a replacement for Events
|
21
|
+
# in Flex/Flash/Apollo. Generally, <code>IMediator</code>implementors
|
22
|
+
# place event listeners on their view components, which they
|
23
|
+
# then handle in the usual way. This may lead to the broadcast of <code>Notification</code>s to
|
24
|
+
# trigger <code>ICommand</code>s or to communicate with other <code>IMediator</code>s. <code>IProxy</code> and
|
25
|
+
# <code>ICommand</code> instances communicate with each other and <code>IMediator</code>s
|
26
|
+
# by broadcasting <code>INotification</code>s.
|
27
|
+
#
|
28
|
+
# A key difference between Flash <code>Event</code>s and PureMVC
|
29
|
+
# <code>Notification</code>s is that <code>Event</code>s follow the
|
30
|
+
# 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
|
31
|
+
# until some parent component handles the <code>Event</code>, while
|
32
|
+
# PureMVC <code>Notification</code>s follow a 'Publish/Subscribe'
|
33
|
+
# pattern. PureMVC classes need not be related to each other in a
|
34
|
+
# parent/child relationship to communicate with one another
|
35
|
+
# using <code>Notification</code>s.
|
36
|
+
#
|
37
|
+
# @see Observer
|
38
|
+
class Notification
|
39
|
+
# @return [String] the name of the notification
|
40
|
+
attr_reader :name
|
41
|
+
|
42
|
+
# @return [Object, nil] the body of the notification
|
43
|
+
attr_accessor :body
|
44
|
+
|
45
|
+
# @return [String, nil] the type of the notification
|
46
|
+
attr_accessor :type
|
47
|
+
|
48
|
+
# The Notification class represents a message with a name, optional body, and optional type.
|
49
|
+
#
|
50
|
+
# @param name [String] the name of the notification
|
51
|
+
# @param body [Object, nil] optional data to pass with the notification
|
52
|
+
# @param type [String, nil] optional type identifier
|
53
|
+
def initialize(name, body = nil, type = nil)
|
54
|
+
@name = name
|
55
|
+
@body = body
|
56
|
+
@type = type
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns a string representation of the notification.
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
def to_s
|
63
|
+
"Notification Name: #{@name}" \
|
64
|
+
"\nBody: #{@body.inspect}" \
|
65
|
+
"\nType: #{@type}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# notifier.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
module PureMVC
|
10
|
+
# A base <code>INotifier</code> implementation.
|
11
|
+
#
|
12
|
+
# <code>MacroCommand</code>, <code>SimpleCommand</code>, <code>Mediator</code>, and <code>Proxy</code>
|
13
|
+
# all need to send <code>Notification</code>s.
|
14
|
+
#
|
15
|
+
# The <code>INotifier</code> interface provides a common method called
|
16
|
+
# <code>send_notification</code> that relieves implementation code of
|
17
|
+
# the necessity to actually construct <code>Notification</code>s.
|
18
|
+
#
|
19
|
+
# The <code>Notifier</code> class, which all the above-mentioned classes
|
20
|
+
# extend, provides an initialized reference to the <code>Facade</code>
|
21
|
+
# Multiton, which is required for the convenience method
|
22
|
+
# for sending <code>Notification</code>s. It also eases implementation,
|
23
|
+
# as these classes have frequent <code>Facade</code> interactions and
|
24
|
+
# usually require access to it anyway.
|
25
|
+
#
|
26
|
+
# NOTE: In the MultiCore version of the framework, there is one caveat:
|
27
|
+
# notifiers cannot send notifications or reach the facade until they
|
28
|
+
# have a valid <code>multiton_key</code>.
|
29
|
+
#
|
30
|
+
# The <code>multiton_key</code> is set:
|
31
|
+
# * on a <code>SimpleCommand</code> when it is executed by the <code>Controller<c/ode>
|
32
|
+
# * on a <code>Mediator</code> when registered with the <code>View</code>
|
33
|
+
# * on a <code>Proxy</code> when registered with the <code>Model</code>
|
34
|
+
#
|
35
|
+
# @see Proxy
|
36
|
+
# @see Facade
|
37
|
+
# @see Mediator
|
38
|
+
# @see MacroCommand
|
39
|
+
# @see SimpleCommand
|
40
|
+
class Notifier
|
41
|
+
# Message Constants
|
42
|
+
MULTITON_MSG = 'multitonKey for this Notifier not yet initialized!'
|
43
|
+
private_constant :MULTITON_MSG
|
44
|
+
|
45
|
+
# @attr_reader [String] The Multiton Key for this app
|
46
|
+
attr_reader :multiton_key
|
47
|
+
|
48
|
+
# Initialize this INotifier instance.
|
49
|
+
#
|
50
|
+
# This is how a Notifier receives its <code>multiton_key</code>.
|
51
|
+
# Any calls to <code>send_notification</code> or attempts to access the <code>facade</code>
|
52
|
+
# will fail until this method has been called.
|
53
|
+
#
|
54
|
+
# Subclasses such as <code>Mediator</code>, <code>Command</code>, or <code>Proxy</code> may override this
|
55
|
+
# method if they need to send notifications or access the <code>Facade</code> instance
|
56
|
+
# as early as possible. However, note that the <code>Facade</code> cannot be accessed
|
57
|
+
# within the constructor of these classes, because <code>initialize_notifier</code>
|
58
|
+
# will not yet have been called at that point.
|
59
|
+
#
|
60
|
+
# @param key [String] the <code>multiton_key</code> this <code>INotifier</code> will use
|
61
|
+
def initialize_notifier(key)
|
62
|
+
@multiton_key = key
|
63
|
+
end
|
64
|
+
|
65
|
+
# Create and send an INotification.
|
66
|
+
#
|
67
|
+
# This method eliminates the need to manually construct
|
68
|
+
# INotification instances in your implementation code.
|
69
|
+
#
|
70
|
+
# @param name [String] the name of the notification
|
71
|
+
# @param body [Object, nil] optional body
|
72
|
+
# @param type [String, nil] optional type
|
73
|
+
def send_notification(name, body = nil, type = nil)
|
74
|
+
facade.send_notification(name, body, type)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Return the Multiton Facade instance
|
78
|
+
#
|
79
|
+
# @raise [RuntimeError] if the <code>multiton_key</code> is not set
|
80
|
+
# @return [IFacade] the facade instance for the notifier's key
|
81
|
+
def facade
|
82
|
+
raise MULTITON_MSG if @multiton_key.nil?
|
83
|
+
|
84
|
+
Facade.get_instance(@multiton_key) { |key| Facade.new(key) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# observer.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
module PureMVC
|
10
|
+
# A base <code>IObserver</code> implementation.
|
11
|
+
#
|
12
|
+
# An <code>Observer</code> is an object that encapsulates information
|
13
|
+
# about an interested object with a method that should
|
14
|
+
# be called when a particular <code>INotification</code> is broadcast.
|
15
|
+
#
|
16
|
+
# In PureMVC, the <code>Observer</code> class assumes these responsibilities:
|
17
|
+
# - Encapsulate the notification (callback) method of the interested object.
|
18
|
+
# - Encapsulate the notification context (<code>self</code>) of the interested object.
|
19
|
+
# - Provide methods for setting the notification method and context.
|
20
|
+
# - Provide a method for notifying the interested object.
|
21
|
+
#
|
22
|
+
# @see View
|
23
|
+
# @see Notification
|
24
|
+
class Observer
|
25
|
+
# @return [Method | nil] notify The callback method to be called on notification.
|
26
|
+
attr_accessor :notify
|
27
|
+
|
28
|
+
# @return [Object | nil] context The object context for the callback.
|
29
|
+
attr_accessor :context
|
30
|
+
|
31
|
+
# Initialize an Observer with a notify method and context.
|
32
|
+
#
|
33
|
+
# @param notify [Method, nil] the callback method to invoke on notification.
|
34
|
+
# @param context [Object, nil] the object context for the callback.
|
35
|
+
def initialize(notify = nil, context = nil)
|
36
|
+
@notify = notify
|
37
|
+
@context = context
|
38
|
+
end
|
39
|
+
|
40
|
+
# Calls the notify method with the given notification.
|
41
|
+
#
|
42
|
+
# @param notification [INotification] the notification to send.
|
43
|
+
def notify_observer(notification)
|
44
|
+
@notify&.call(notification)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Compares the given object with the Observer's context.
|
48
|
+
#
|
49
|
+
# @param object [Object] the object to compare.
|
50
|
+
# @return [Boolean] true if the given object is the same as the context.
|
51
|
+
def compare_notify_context?(object)
|
52
|
+
object.equal?(@context)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# proxy.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
module PureMVC
|
10
|
+
# A base <code>IProxy</code> implementation.
|
11
|
+
#
|
12
|
+
# In PureMVC, <code>Proxy</code> classes are used to manage parts of the application's data model.
|
13
|
+
#
|
14
|
+
# A <code>Proxy</code> might simply manage a reference to a local data object, in which case
|
15
|
+
# interacting with it might involve setting and getting of its data in a synchronous fashion.
|
16
|
+
#
|
17
|
+
# <code>Proxy</code> classes are also used to encapsulate the application's interaction with
|
18
|
+
# remote services to save or retrieve data. In this case, we adopt an asynchronous idiom:
|
19
|
+
# setting data (or calling a method) on the <code>Proxy</code> and listening for a <code>Notification</code>
|
20
|
+
# to be sent when the <code>Proxy</code> has retrieved the data from the service.
|
21
|
+
#
|
22
|
+
# @see Model
|
23
|
+
class Proxy < Notifier
|
24
|
+
# The name of the <code>Proxy</code>.
|
25
|
+
NAME = 'Proxy'
|
26
|
+
public_constant :NAME
|
27
|
+
|
28
|
+
# @return [String] The proxy name
|
29
|
+
attr_reader :name
|
30
|
+
|
31
|
+
# @return [Object, nil] The data managed by the proxy
|
32
|
+
attr_accessor :data
|
33
|
+
|
34
|
+
# Initializes a new Proxy instance.
|
35
|
+
#
|
36
|
+
# @param [String, nil] name the name of the proxy
|
37
|
+
# @param [Object, nil] data optional data to be managed by the proxy
|
38
|
+
def initialize(name = nil, data = nil)
|
39
|
+
super()
|
40
|
+
@name = name || NAME
|
41
|
+
@data = data
|
42
|
+
end
|
43
|
+
|
44
|
+
# Called by the Model when the Proxy is registered
|
45
|
+
def on_register; end
|
46
|
+
|
47
|
+
# Called by the Model when the Proxy is removed
|
48
|
+
def on_remove; end
|
49
|
+
end
|
50
|
+
end
|
data/src/puremvc.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# puremvc.rb
|
4
|
+
# PureMVC Ruby Multicore
|
5
|
+
#
|
6
|
+
# Copyright(c) 2025 Saad Shams <saad.shams@puremvc.org>
|
7
|
+
# Your reuse is governed by the BSD 3-Clause License
|
8
|
+
|
9
|
+
require_relative 'core/controller'
|
10
|
+
require_relative 'core/model'
|
11
|
+
require_relative 'core/view'
|
12
|
+
require_relative 'patterns/observer/notifier'
|
13
|
+
require_relative 'patterns/command/simple_command'
|
14
|
+
require_relative 'patterns/command/macro_command'
|
15
|
+
require_relative 'patterns/facade/facade'
|
16
|
+
require_relative 'patterns/mediator/mediator'
|
17
|
+
require_relative 'patterns/observer/notification'
|
18
|
+
require_relative 'patterns/observer/observer'
|
19
|
+
require_relative 'patterns/proxy/proxy'
|
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
|
-
|
5
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
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
|
-
|
18
|
-
|
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
|
-
|
24
|
-
-
|
25
|
-
|
26
|
-
-
|
27
|
-
-
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- sig/core/controller.rbs
|
24
|
+
- sig/core/model.rbs
|
25
|
+
- sig/core/view.rbs
|
26
|
+
- sig/interfaces/i_command.rbs
|
27
|
+
- sig/interfaces/i_controller.rbs
|
28
|
+
- sig/interfaces/i_facade.rbs
|
29
|
+
- sig/interfaces/i_mediator.rbs
|
30
|
+
- sig/interfaces/i_model.rbs
|
31
|
+
- sig/interfaces/i_notification.rbs
|
32
|
+
- sig/interfaces/i_notifier.rbs
|
33
|
+
- sig/interfaces/i_observer.rbs
|
34
|
+
- sig/interfaces/i_proxy.rbs
|
35
|
+
- sig/interfaces/i_view.rbs
|
36
|
+
- sig/patterns/command/macro_command.rbs
|
37
|
+
- sig/patterns/command/simple_command.rbs
|
38
|
+
- sig/patterns/facade/facade.rbs
|
39
|
+
- sig/patterns/mediator/mediator.rbs
|
40
|
+
- sig/patterns/observer/notification.rbs
|
41
|
+
- sig/patterns/observer/notifier.rbs
|
42
|
+
- sig/patterns/observer/observer.rbs
|
43
|
+
- sig/patterns/proxy/proxy.rbs
|
44
|
+
- src/core/controller.rb
|
45
|
+
- src/core/model.rb
|
46
|
+
- src/core/view.rb
|
47
|
+
- src/patterns/command/macro_command.rb
|
48
|
+
- src/patterns/command/simple_command.rb
|
49
|
+
- src/patterns/facade/facade.rb
|
50
|
+
- src/patterns/mediator/mediator.rb
|
51
|
+
- src/patterns/observer/notification.rb
|
52
|
+
- src/patterns/observer/notifier.rb
|
53
|
+
- src/patterns/observer/observer.rb
|
54
|
+
- src/patterns/proxy/proxy.rb
|
55
|
+
- src/puremvc.rb
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
none: false
|
50
|
-
requirements:
|
66
|
+
require_paths:
|
67
|
+
- src
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
51
70
|
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
|
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:
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
60
78
|
requirements: []
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|