Skip to content

Commit

Permalink
Organises the app with libraries and settings
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <[email protected]>
  • Loading branch information
HashNuke committed Mar 7, 2012
1 parent 064341d commit 9a2a2e7
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/models/activity_observer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ActivityObserver < ActiveRecord::Observer

def after_save(activity)
Kandan::Config.broadcaster.broadcast(activity.attributes)
end
end
9 changes: 7 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
<html>
<head>
<title>Kandan</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= stylesheet_link_tag "application", :media => "all" %>

<%- Kandan::Config.broadcaster.assets.each do |asset| %>
<%= javascript_include_tag asset %>
<%- end %>

<%= javascript_include_tag "application" %>
<%= javascript_include_tag "#{ENV['FAYEJS']}.js" %>

<%= csrf_meta_tags %>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Application < Rails::Application
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
config.active_record.observers = :activity_observer

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
Expand Down
1 change: 0 additions & 1 deletion config/initializers/faye.rb

This file was deleted.

6 changes: 6 additions & 0 deletions config/initializers/kandan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dir["#{Rails.root}/lib/broadcasters/**/*.rb"].each do |file|
require file
end

require "#{Rails.root}/lib/kandan_config.rb"

9 changes: 9 additions & 0 deletions config/kandan_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
########################
# Kandan settings file
########################


# What should be used for broadcasting messages to browser?
# valid options: Faye
:broadcaster:
:name: "Faye"
18 changes: 18 additions & 0 deletions lib/broadcasters/faye.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Broadcasters
class Faye
class << self
def broadcast(channel, message)
# NOTE FAYE_CLIENT is set in the config.ru file due to the faye bug
if defined?(FAYE_CLIENT)
FAYE_CLIENT.publish channel, message
else
puts "OOPS! FAYE_CLIENT is not defined"
end
end

def assets
["/remote/faye.js"]
end
end
end
end
15 changes: 15 additions & 0 deletions lib/kandan_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Kandan
class Config

class << self
def options
@config ||= YAML.load_file "#{Rails.root}/config/kandan_settings.yml"
end

def broadcaster
Broadcasters.const_get(Kandan::Config.options[:broadcaster][:name])
end
end

end
end

0 comments on commit 9a2a2e7

Please sign in to comment.