Class: Pushify::Rails::Assets

Inherits:
Object
  • Object
show all
Defined in:
lib/pushify/rails.rb

Class Method Summary collapse

Class Method Details

.asset_body(asset) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pushify/rails.rb', line 31

def self.asset_body(asset)
  if (asset == "pushify.js")
    [
      File.open(self.path_to_asset("json.js")).read, 
      File.open(self.path_to_asset("swfobject.js")).read, 
      File.open(self.path_to_asset("juggernaut.js")).read, 
      File.open(self.path_to_asset("pushify.js")).read,
      Pushify.juggernaut_src
    ].join("\n\n")
  else
    File.open(self.path_to_asset(asset)).read
  end
end

.assetsObject



23
24
25
26
27
28
29
# File 'lib/pushify/rails.rb', line 23

def self.assets
  {
    "/pushify/pushify.js" => ["text/application", "pushify.js"],
    "/pushify/juggernaut.swf" => ["application/x-shockwave-flash", "juggernaut.swf"],
    "/pushify/expressinstall.swf" => ["application/x-shockwave-flash", "/pushify/expressinstall.swf"]
  }
end

.includes?(path) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pushify/rails.rb', line 50

def self.includes?(path)
  self.assets.keys.include?(just_the_path(path))
end

.just_the_path(path) ⇒ Object



45
46
47
48
# File 'lib/pushify/rails.rb', line 45

def self.just_the_path(path)
  m = path.match(/https?:\/\/[-A-Za-z0-9\.:]*(\/.*)/)
  m ? m[1] : path
end

.path_to_asset(asset) ⇒ Object



19
20
21
# File 'lib/pushify/rails.rb', line 19

def self.path_to_asset(asset)
  File.join(File.dirname(__FILE__), "..", "..", "install", asset)
end

.response(path) ⇒ Object



54
55
56
57
# File 'lib/pushify/rails.rb', line 54

def self.response(path)
  asset = self.assets[just_the_path(path)]
  [200, {"Content-Type" => asset[0]}, [self.asset_body(asset[1])]]
end