-
-
Save cj/98a249a35843ace157f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "observer" | |
module Widgets | |
def self.setup app | |
app.settings[:widgets] = [] | |
end | |
def widgets list = false | |
event = Events.new | |
Base.new(res, req, settings, event) | |
# settings[:widgets].each do |widget| | |
# "Widgets::#{widget}".constantize.new(res, req, settings, event) | |
# end | |
event.trigger :test | |
true | |
end | |
module ClassMethods | |
def has_widgets *list | |
list.each do |widget| | |
settings[:widgets] << widget | |
end | |
end | |
end | |
class Events | |
include Observable | |
def trigger event | |
ap "trigger: #{event}" | |
notify_observers Time.now, event | |
end | |
end | |
class Notify < Struct.new(:res, :req, :settings, :event) | |
def initialize res, req, settings, event | |
@res, @req, @settings, @event = res, req, settings, event | |
event.add_observer self, :trigger_event | |
end | |
end | |
class Base < Notify | |
def trigger_event event | |
ap '=======================' | |
ap "#{event} triggered!!!!!" | |
ap '=======================' | |
end | |
class << self | |
# attr_accessor :events | |
def respond_to moo, options = {} | |
# @events ||= [] | |
# @events << [event, options] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment