Skip to content

Instantly share code, notes, and snippets.

@cj

cj/widgets.rb Secret

Created February 26, 2014 05:26
Show Gist options
  • Save cj/98a249a35843ace157f4 to your computer and use it in GitHub Desktop.
Save cj/98a249a35843ace157f4 to your computer and use it in GitHub Desktop.
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