Module: TheForce::RemoteIncludes

Defined in:
lib/the_force/remote_includes.rb

Constant Summary collapse

@@remotes =
[]

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



7
8
9
# File 'lib/the_force/remote_includes.rb', line 7

def self.[](name)
  @@remotes.detect {|remote| remote.name == name }
end

.add(attrs) ⇒ Object



15
16
17
18
# File 'lib/the_force/remote_includes.rb', line 15

def self.add(attrs)
  attrs[:name] ||= attrs[:url]
  @@remotes << RemoteInclude.new(attrs) unless attrs[:url].blank?
end

.cache_from_partial(key, partial) ⇒ Object



30
31
32
33
# File 'lib/the_force/remote_includes.rb', line 30

def self.cache_from_partial(key, partial)
  av = ActionView::Base.new(Rails::Configuration.new.view_path)
  Rails.cache.write(key, av.render(:partial => partial))
end

.cache_url_with_partial_fallback(url, key, partial = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/the_force/remote_includes.rb', line 20

def self.cache_url_with_partial_fallback(url, key, partial = nil)
  begin
    response = Net::HTTP.get_response(URI.parse(url))
    Rails.cache.write(key, response.body) if response.class == Net::HTTPOK
  rescue Exception => e
  ensure
    cache_from_partial(key, partial) if partial and not Rails.cache.read(key)
  end
end

.recache!Object



35
36
37
38
39
# File 'lib/the_force/remote_includes.rb', line 35

def self.recache!
  Array(@@remotes).each do |remote|
    remote.recache!
  end
end

.remotesObject



11
12
13
# File 'lib/the_force/remote_includes.rb', line 11

def self.remotes
  @@remotes
end