Module: Ironhide::Includer::ClassMethods
- Included in:
- Ironhide::Includer
- Defined in:
- lib/ironhide/includer.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #cache_key(url) ⇒ Object
- #cache_read(url) ⇒ Object
- #cache_write(url, value, timeout) ⇒ Object
- #get(url, timeout = default_timeout) ⇒ Object
Instance Attribute Details
#default_timeout ⇒ Object
9 10 11 |
# File 'lib/ironhide/includer.rb', line 9 def default_timeout @default_timeout ||= 600 end |
Instance Method Details
#cache_key(url) ⇒ Object
37 38 39 |
# File 'lib/ironhide/includer.rb', line 37 def cache_key(url) "Ironhide::Includer::#{Digest::MD5.hexdigest(url)}" end |
#cache_read(url) ⇒ Object
27 28 29 30 |
# File 'lib/ironhide/includer.rb', line 27 def cache_read(url) return nil unless defined? Rails Rails.cache.read(cache_key(url)) end |
#cache_write(url, value, timeout) ⇒ Object
32 33 34 35 |
# File 'lib/ironhide/includer.rb', line 32 def cache_write(url, value, timeout) return unless defined? Rails Rails.cache.write(cache_key(url), value, :expires_in => timeout) end |
#get(url, timeout = default_timeout) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ironhide/includer.rb', line 13 def get(url, timeout = default_timeout) cached = cache_read(url) return cached unless cached.nil? response = HTTPClient.get(url) if response.status_code == 200 content = response.body.content cache_write(url, content, timeout) content else nil end end |