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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +11 -0
- data/LICENSE +28 -0
- data/README.md +88 -0
- data/lib/core/controller.rb +177 -0
- data/lib/core/model.rb +133 -0
- data/lib/core/view.rb +230 -0
- data/lib/patterns/command/macro_command.rb +81 -0
- data/lib/patterns/command/simple_command.rb +28 -0
- data/lib/patterns/facade/facade.rb +267 -0
- data/lib/patterns/mediator/mediator.rb +56 -0
- data/lib/patterns/observer/notification.rb +68 -0
- data/lib/patterns/observer/notifier.rb +87 -0
- data/lib/patterns/observer/observer.rb +55 -0
- data/lib/patterns/proxy/proxy.rb +50 -0
- data/lib/puremvc.rb +19 -0
- data/sig/lib/core/controller.rbs +40 -0
- data/sig/lib/core/model.rbs +38 -0
- data/sig/lib/core/view.rbs +42 -0
- data/sig/lib/interfaces/i_command.rbs +18 -0
- data/sig/lib/interfaces/i_controller.rbs +52 -0
- data/sig/lib/interfaces/i_facade.rbs +116 -0
- data/sig/lib/interfaces/i_mediator.rbs +60 -0
- data/sig/lib/interfaces/i_model.rbs +38 -0
- data/sig/lib/interfaces/i_notification.rbs +52 -0
- data/sig/lib/interfaces/i_notifier.rbs +48 -0
- data/sig/lib/interfaces/i_observer.rbs +56 -0
- data/sig/lib/interfaces/i_proxy.rbs +36 -0
- data/sig/lib/interfaces/i_view.rbs +71 -0
- data/sig/lib/patterns/command/macro_command.rbs +18 -0
- data/sig/lib/patterns/command/simple_command.rbs +11 -0
- data/sig/lib/patterns/facade/facade.rbs +48 -0
- data/sig/lib/patterns/mediator/mediator.rbs +18 -0
- data/sig/lib/patterns/observer/notification.rbs +18 -0
- data/sig/lib/patterns/observer/notifier.rbs +17 -0
- data/sig/lib/patterns/observer/observer.rbs +20 -0
- data/sig/lib/patterns/proxy/proxy.rbs +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
@@ -1,59 +0,0 @@
|
|
1
|
-
# A MacroCommand maintains an list of Command Class references called SubCommands
|
2
|
-
#
|
3
|
-
# When execute is called, the MacroCommand instantiates and calls execute on each
|
4
|
-
# of its SubCommands.Each SubCommand will be passed a reference to the original
|
5
|
-
# Notification that was passed to the MacroCommand's execute method.
|
6
|
-
#
|
7
|
-
# Unlike SimpleCommand, your subclass should not override execute, but instead,
|
8
|
-
# should override the initialize_macro_command method, calling add_sub_command
|
9
|
-
# once for each SubCommand to be executed.
|
10
|
-
class MacroCommand
|
11
|
-
attr_accessor :sub_commands
|
12
|
-
|
13
|
-
|
14
|
-
# You should not need to define a constructor,
|
15
|
-
# instead, override the initialize_macro_command method.
|
16
|
-
#
|
17
|
-
# If your subclass does define a constructor, be sure to call super.
|
18
|
-
def initialize
|
19
|
-
@sub_commands = []
|
20
|
-
initialize_macro_command
|
21
|
-
end
|
22
|
-
|
23
|
-
# Initialize the MacroCommand.
|
24
|
-
#
|
25
|
-
# In your subclass, override this method to initialize the MacroCommand's
|
26
|
-
# SubCommand list with Command class references like this:
|
27
|
-
#
|
28
|
-
# <tt>
|
29
|
-
# def initialize_macro_command
|
30
|
-
# add_sub_command( FirstCommand.new )
|
31
|
-
# add_sub_command( SecondCommand.new )
|
32
|
-
# add_sub_command( ThirdCommand.new )
|
33
|
-
# end
|
34
|
-
# </tt>
|
35
|
-
#
|
36
|
-
# Note that SubCommands may be MacroCommands or SimpleCommands.
|
37
|
-
def initialize_macro_command
|
38
|
-
raise NotImplementedError
|
39
|
-
end
|
40
|
-
|
41
|
-
# Add a SubCommand
|
42
|
-
#
|
43
|
-
#The Subcommands will be called in First In/First Out (FIFO) order.
|
44
|
-
def add_sub_command(command)
|
45
|
-
@sub_commands << command
|
46
|
-
end
|
47
|
-
|
48
|
-
# Execute this MacroCommand's Subcommands. The SubCommands will be called in First
|
49
|
-
# In/First Out (FIFO) order.
|
50
|
-
def execute(notification)
|
51
|
-
@sub_commands.each do |command|
|
52
|
-
command.new().execute(notification)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
58
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
59
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# Your subclass should override the execute method where your business logic
|
2
|
-
# will handle the Notification.
|
3
|
-
class SimpleCommand < Notifier
|
4
|
-
|
5
|
-
# Fulfill the use-case initiated by the given Notification.
|
6
|
-
#
|
7
|
-
# In the Command Pattern, an application use-case typically
|
8
|
-
# begins with some user action, which results in an Notification being broadcast, which
|
9
|
-
# is handled by business logic in the execute method of an Command.
|
10
|
-
def execute(notification)
|
11
|
-
#override if you want to do something on this event
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
16
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
17
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,161 +0,0 @@
|
|
1
|
-
# In PureMVC, the Facade class assumes these responsibilities:
|
2
|
-
#
|
3
|
-
# * Initializing the Model, View and Controller Singletons.
|
4
|
-
# * Providing all the methods defined by the Model, View, & Controller.
|
5
|
-
# * Providing the ability to override the specific Model, View and Controller Singletons created.
|
6
|
-
# * Providing a single point of contact to the application for registering Commands and notifying Observers
|
7
|
-
class Facade
|
8
|
-
include Singleton
|
9
|
-
|
10
|
-
attr_accessor :model, :view, :controller
|
11
|
-
|
12
|
-
# This Facade implementation is a Singleton, so you can not call the constructor
|
13
|
-
# directly, but instead call the static Singleton Factory method Facade.instance
|
14
|
-
def initialize
|
15
|
-
initialize_facade
|
16
|
-
end
|
17
|
-
|
18
|
-
# Initialize the Singleton Facade instance.
|
19
|
-
#
|
20
|
-
# Called automatically by the constructor. Override in your
|
21
|
-
# subclass to do any subclass specific initializations. Be sure to call super.
|
22
|
-
def initialize_facade
|
23
|
-
initialize_model
|
24
|
-
initialize_view
|
25
|
-
initialize_controller
|
26
|
-
end
|
27
|
-
|
28
|
-
# Initialize the Controller.
|
29
|
-
#
|
30
|
-
# Called by the initialize_facade method.
|
31
|
-
# Override this method in your subclass of Facade if one or both of the following are true:
|
32
|
-
# * You wish to initialize a different Controller.
|
33
|
-
# * You have Commands to register with the Controller at startup.
|
34
|
-
#
|
35
|
-
# If you don't want to initialize a different Controller,
|
36
|
-
# call super at the beginning of your method, then register Commands.
|
37
|
-
def initialize_controller
|
38
|
-
return unless @controller.nil?
|
39
|
-
@controller = Controller.instance
|
40
|
-
end
|
41
|
-
|
42
|
-
# Initialize the Model.
|
43
|
-
#
|
44
|
-
# Called by the initialize_facade method.
|
45
|
-
# Override this method in your subclass of Facade if one or both of the following are true:
|
46
|
-
# * You wish to initialize a different Model.
|
47
|
-
# * You have Proxys to register with the Model that do not retrieve a reference to
|
48
|
-
# the Facade at construction time.
|
49
|
-
#
|
50
|
-
# If you don't want to initialize a different Model,
|
51
|
-
# call super at the beginning of your method, then register Proxys.
|
52
|
-
#
|
53
|
-
# Note: This method is rarely overridden; in practice you are morelikely to use a
|
54
|
-
# Command to create and register Proxys with the Model, since Proxys with mutable
|
55
|
-
# data will likely need to send Notifications and thus will likely want to fetch a
|
56
|
-
# reference to the Facade during their construction.
|
57
|
-
def initialize_model
|
58
|
-
return unless @model.nil?
|
59
|
-
@model = Model.instance
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# Initialize the View.
|
64
|
-
#
|
65
|
-
# Called by the initialize_facade method.
|
66
|
-
# Override this method in your subclass of Facade if one or both of the following are true:
|
67
|
-
# * You wish to initialize a different View.
|
68
|
-
# * You have Observers to register with the View.
|
69
|
-
#
|
70
|
-
# If you don't want to initialize a different View, call super at the beginning of your
|
71
|
-
# method, then register Mediator instances.
|
72
|
-
#
|
73
|
-
# Note: This method is rarely overridden; in practice you are more likely to use a
|
74
|
-
# Command to create and register Mediators with the View, since Mediator instances
|
75
|
-
# will need to send Notifications and thus will likely want to fetch a reference
|
76
|
-
# to the Facade during their construction.
|
77
|
-
def initialize_view
|
78
|
-
return unless @view.nil?
|
79
|
-
@view = View.instance
|
80
|
-
end
|
81
|
-
|
82
|
-
# Register an Command with the Controller by Notification name.
|
83
|
-
def register_command(name, command_class_ref)
|
84
|
-
@controller.register_command(name, command_class_ref)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Remove a previously registered Command to Notification mapping from the Controller.
|
88
|
-
def remove_command(notification_name)
|
89
|
-
@controller.remove_command(notification_name)
|
90
|
-
end
|
91
|
-
|
92
|
-
# Check if a Command is registered for a given Notification
|
93
|
-
def has_command?(notification_name)
|
94
|
-
@controller.has_command?(notification_name)
|
95
|
-
end
|
96
|
-
|
97
|
-
# Register a Proxy with the Model by name.
|
98
|
-
def register_proxy(proxy)
|
99
|
-
@model.register_proxy(proxy)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Retrieve a Proxy with the Model by name.
|
103
|
-
def retrieve_proxy(proxy_name)
|
104
|
-
@model.retrieve_proxy(proxy_name)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Remove an Proxy from the Model by name.
|
108
|
-
def remove_proxy(proxy_name)
|
109
|
-
proxy = @model.remove_proxy(proxy_name) unless @model.nil?
|
110
|
-
proxy
|
111
|
-
end
|
112
|
-
|
113
|
-
# Check if a Proxy is registered
|
114
|
-
def has_proxy?(proxy_name)
|
115
|
-
@model.has_proxy?(proxy_name)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Register a Mediator with the View.
|
119
|
-
def register_mediator(mediator)
|
120
|
-
@view.register_mediator(mediator) unless @view.nil?
|
121
|
-
end
|
122
|
-
|
123
|
-
# Retrieve a Mediator from the View.
|
124
|
-
def retrieve_mediator(mediator_name)
|
125
|
-
@view.retrieve_mediator(mediator_name)
|
126
|
-
end
|
127
|
-
|
128
|
-
# Remove a Mediator from the View.
|
129
|
-
def remove_mediator(mediator_name)
|
130
|
-
mediator = @view.remove_mediator(mediator_name) unless @view.nil?
|
131
|
-
mediator
|
132
|
-
end
|
133
|
-
|
134
|
-
# Check if a Mediator is registered or not
|
135
|
-
def has_mediator?(mediator_name)
|
136
|
-
@view.has_mediator?(mediator_name)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Create and send a Notification.
|
140
|
-
#
|
141
|
-
# Keeps us from having to construct new notification
|
142
|
-
# instances in our implementation code.
|
143
|
-
def send_notification(notification_name, body=nil, type=nil)
|
144
|
-
notify_observers(Notification.new(notification_name, body, type))
|
145
|
-
end
|
146
|
-
|
147
|
-
# Notify Observers.
|
148
|
-
#
|
149
|
-
# This method is left public mostly for backward compatibility, and to allow
|
150
|
-
# you to send custom notification classes using the facade.
|
151
|
-
#
|
152
|
-
# Usually you should just call send_notification and pass the parameters,
|
153
|
-
# never having to construct the notification yourself.
|
154
|
-
def notify_observers(notification)
|
155
|
-
@view.notify_observers(notification) unless @view.nil?
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
160
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
161
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,37 +0,0 @@
|
|
1
|
-
class Mediator < Notifier
|
2
|
-
|
3
|
-
# The name of the Mediator
|
4
|
-
# Typically, a Mediator will be written to serve one specific control or group
|
5
|
-
# controls and so,will not have a need to be dynamically named.
|
6
|
-
attr_accessor :name
|
7
|
-
attr_accessor :view
|
8
|
-
|
9
|
-
def initialize(name="Mediator", view=nil )
|
10
|
-
@name = name
|
11
|
-
@view = view
|
12
|
-
end
|
13
|
-
|
14
|
-
# List the Notification names this Mediator is interested in being notified of.
|
15
|
-
def list_notification_interests
|
16
|
-
[]
|
17
|
-
end
|
18
|
-
|
19
|
-
# Handle Notifications.
|
20
|
-
#
|
21
|
-
# Typically this will be handled in a switch statement, with one 'case' entry
|
22
|
-
# per Notification the Mediator is interested in.
|
23
|
-
def handle_notification(note)
|
24
|
-
#override if you want to do something on this event
|
25
|
-
end
|
26
|
-
|
27
|
-
# Called by the View when the Mediator is registered
|
28
|
-
def on_register
|
29
|
-
#override if you want to do something on this event
|
30
|
-
end
|
31
|
-
|
32
|
-
# Called by the View when the Mediator is removed
|
33
|
-
def on_remove
|
34
|
-
#override if you want to do something on this event
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# PureMVC does not rely upon underlying event models such as the one provided with Flash.
|
2
|
-
#
|
3
|
-
# The Observer Pattern as implemented within PureMVC exists to support event-driven
|
4
|
-
# communication between the application and the actors of the MVC triad.
|
5
|
-
#
|
6
|
-
# Notifications are not meant to be a replacement for Events. Generally, Mediator
|
7
|
-
# implementors place event listeners on their view components, which they
|
8
|
-
# then handle in the usual way. This may lead to the broadcast of Notifications to
|
9
|
-
# trigger Commands or to communicate with other Mediators. Proxy and Command
|
10
|
-
# instances communicate with each other and Mediators by broadcasting Notifications.
|
11
|
-
#
|
12
|
-
# A key difference between UI Events and PureMVC Notifications is that Events
|
13
|
-
# follow the 'Chain of Responsibility' pattern, 'bubbling' up the display hierarchy
|
14
|
-
# until some parent component handles the Event, while PureMVC Notifications follow
|
15
|
-
# a 'Publish/Subscribe' pattern. PureMVC classes need not be related to each other in a
|
16
|
-
# parent/child relationship in order to communicate with one another using Notifications.
|
17
|
-
class Notification
|
18
|
-
|
19
|
-
attr_accessor :name, :body, :type
|
20
|
-
|
21
|
-
def initialize(name=nil, body=nil, type=nil)
|
22
|
-
@name = name
|
23
|
-
@body = body
|
24
|
-
@type = type
|
25
|
-
end
|
26
|
-
|
27
|
-
# Get the string representation of the Notification instance.
|
28
|
-
def to_s
|
29
|
-
msg = "Notifcation Name: #{@name}"
|
30
|
-
msg += "\nBody: #{@body.inspect}"
|
31
|
-
msg += "\nType: #{@type.inspect}"
|
32
|
-
msg
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
37
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
38
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# MacroCommand, Command, Mediator and Proxy all have a need to send Notifications.
|
2
|
-
#
|
3
|
-
# The Notifier provides a common method called send_notification that relieves
|
4
|
-
# implementation code of the necessity to actually construct Notifications.
|
5
|
-
#
|
6
|
-
# The Notifier class, which all of the above mentioned classes extend, provides
|
7
|
-
# an initialized reference to the Facade Singleton, which is required for the
|
8
|
-
# convienience method for sending Notifications, but also eases implementation
|
9
|
-
# as these classes have frequent Facade interactions and usually require access
|
10
|
-
# to the facade anyway.
|
11
|
-
class Notifier
|
12
|
-
|
13
|
-
# Create and send an Notification.
|
14
|
-
#
|
15
|
-
# Keeps us from having to construct new Notification instances in our implementation code.
|
16
|
-
def send_notification(notification_name, body=nil, type=nil)
|
17
|
-
facade.send_notification(notification_name, body, type)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Local reference to the Facade Singleton
|
21
|
-
def facade
|
22
|
-
Facade.instance
|
23
|
-
end
|
24
|
-
end
|
25
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
26
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
27
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# An Observer is an object that encapsulates information about an interested object
|
2
|
-
# with a method that should be called when a particular Notification is broadcast.
|
3
|
-
#
|
4
|
-
# In PureMVC, the Observer class assumes these responsibilities:
|
5
|
-
# * Encapsulate the notification (callback) method of the interested object.
|
6
|
-
# * Encapsulate the notification context (this) of the interested object.
|
7
|
-
# * Provide methods for setting the notification method and context.
|
8
|
-
# * Provide a method for notifying the interested object.
|
9
|
-
class Observer
|
10
|
-
attr_accessor :notify, :context
|
11
|
-
|
12
|
-
# The notification method on the interested object should take
|
13
|
-
# one parameter of type Notification
|
14
|
-
def initialize(notify=nil, context=nil)
|
15
|
-
@notify = notify
|
16
|
-
@context = context
|
17
|
-
end
|
18
|
-
|
19
|
-
# Notify the interested object.
|
20
|
-
def notify_observer(notification)
|
21
|
-
@context.send(@notify, notification)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Compare an object to the notification context.
|
25
|
-
def compare_notify_context(object)
|
26
|
-
@context.equal?(object)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
30
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
31
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# In PureMVC, Proxy classes are used to manage parts of the application's data model.
|
2
|
-
#
|
3
|
-
# A Proxy might simply manage a reference to a local data object, in which case
|
4
|
-
# interacting with it might involve setting and getting of its data in synchronous
|
5
|
-
# fashion.
|
6
|
-
#
|
7
|
-
# Proxy classes are also used to encapsulate the application's interaction with
|
8
|
-
# remote services to save or retrieve data, in which case, we adopt an asyncronous
|
9
|
-
# idiom; setting data (or calling a method) on the Proxy and listening for a
|
10
|
-
# Notification to be sent when the Proxy has retrieved the data from the service.
|
11
|
-
class Proxy
|
12
|
-
|
13
|
-
attr_accessor :name, :data
|
14
|
-
def initialize(proxy_name, data=nil)
|
15
|
-
@name = proxy_name
|
16
|
-
@data = data
|
17
|
-
end
|
18
|
-
|
19
|
-
# Called by the Model when the Proxy is registered
|
20
|
-
def on_register
|
21
|
-
#override if you want to do something on this event
|
22
|
-
end
|
23
|
-
|
24
|
-
# Called by the Model when the Proxy is removed
|
25
|
-
def on_remove
|
26
|
-
#override if you want to do something on this event
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
# PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
31
|
-
# PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
32
|
-
# Your reuse is governed by the Creative Commons Attribution 3.0 License
|
data/version.txt
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
PureMVC Port to Ruby by Jake Dempsey <jake.dempsey@puremvc.org>
|
2
|
-
PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
3
|
-
--------------------------------------------------------------------------
|
4
|
-
Release Date: 1/14/09
|
5
|
-
Platform: Ruby
|
6
|
-
Version: 1
|
7
|
-
Revision: 0
|
8
|
-
Authors: Jake Dempsey <jake.dempsey@puremvc.org>
|
9
|
-
License: Creative Commons Attribution 3.0 Unported License
|
10
|
-
--------------------------------------------------------------------------
|
11
|
-
|
12
|
-
1.0 - Initial upload of ported code, equivalent to AS3 Standard Version 2.0.4.
|