Module: PushRoutes

Defined in:
lib/push_routes.rb,
lib/push_routes/engine.rb,
lib/push_routes/helpers.rb,
lib/push_routes/version.rb,
lib/push_routes/push_route_url.rb,
app/helpers/push_routes/application_helper.rb

Overview

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…

Defined Under Namespace

Modules: ApplicationHelper, Helpers Classes: Engine, PushRouteUrl

Constant Summary collapse

VERSION =
"0.0.6"
@@redis =
nil
@@controllers =
Set.new

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.NODE_URLObject

Returns the value of attribute NODE_URL.



16
17
18
# File 'lib/push_routes.rb', line 16

def NODE_URL
  @NODE_URL
end

Class Method Details

.active_routesObject



77
78
79
# File 'lib/push_routes.rb', line 77

def self.active_routes
  PushRoutes.controllers.flat_map {|c| c.push_routes.map {|k,v| v.source}}
end

.class_prefixes(string) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/push_routes.rb', line 47

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

.controllersObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/push_routes.rb', line 58

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

.newGetRoutesObject



21
22
23
24
25
26
27
28
29
# 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

.redisObject



43
44
45
# File 'lib/push_routes.rb', line 43

def self.redis
  @@redis
end

.REDIS_URLObject



31
32
33
# File 'lib/push_routes.rb', line 31

def self.REDIS_URL
  @@redis.client.options[:url] if @@redis
end

.REDIS_URL=(x) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/push_routes.rb', line 35

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