module PushRoutes
TODO: setup the add_trigger method to take a block and do the rails magic which will take functions defined with regular names and attach them
That rails magic might not be possible...
Constants
- VERSION
Attributes
NODE_URL[RW]
Public Class Methods
REDIS_URL()
click to toggle source
# File lib/push_routes.rb, line 31 def self.REDIS_URL @@redis.client.options[:url] if @@redis end
REDIS_URL=(x)
click to toggle source
# File lib/push_routes.rb, line 44 def self.REDIS_URL= (x) begin @@redis = Redis.new(:url => x); rescue warn "Failed to connect to redis server. Push Routes will not work" end end
active_routes()
click to toggle source
# File lib/push_routes.rb, line 86 def self.active_routes PushRoutes.controllers.flat_map {|c| c.push_routes.map {|k,v| v.source}} end
class_prefixes(string)
click to toggle source
# File lib/push_routes.rb, line 56 def self.class_prefixes(string) res = [] pos = 0 while(string.index("::",pos)) pos = string.index("::",pos) res << string[0..pos-1] pos += 2 end res << string[0..-1] end
controllers()
click to toggle source
# File lib/push_routes.rb, line 67 def self.controllers Dir[Rails.root.join('app','controllers','**','*.rb')].map do |file| #Note: This may break if the directory structure has /app/controllers multiple times. #We want to match everything after the first app/controllers after the project root Object.const_get(/^.*?\/app\/controllers\/(.*?).rb$/.match(file)[1].camelize) end # Dir[Rails.root.join('app','controllers','**','*.rb')].each do |file| # #Note: This may break if the directory structure has /app/controllers multiple times. # #We want to match everything after the first app/controllers after the project root # controller_name = /^.*?\/app\/controllers\/(.*?).rb$/.match(file)[1].camelize # class_prefixes(controller_name)[0..-2].each do |name| # Object.const_get(name) # end # end end
newGetRoutes()
click to toggle source
# File lib/push_routes.rb, line 21 def self.newGetRoutes hash = {} PushRoutes.controllers.each do |c| c.push_routes.each do |k,v| hash[v.source] = c.controller_path+"#"+k.to_s if v.isNew end end return hash end
redis()
click to toggle source
# File lib/push_routes.rb, line 52 def self.redis @@redis end
trigger(route, type: '', data: 'placeholder')
click to toggle source
# File lib/push_routes.rb, line 35 def self.trigger(route, type: '', data: 'placeholder') return warn "PushRoutes: Redis not configured properly" if PushRoutes.redis.nil? begin PushRoutes.redis.publish 'rt-change', {channel: route, type: type, data: data}.to_json rescue Redis::CannotConnectError => e warn "PushRoutes cannot reach the redis server" end end