Class: Middleman::CachingProxy::Extension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman/caching_proxy/extension.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ Extension

Returns a new instance of Extension.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/middleman/caching_proxy/extension.rb', line 39

def initialize(app, options_hash = {}, &block)
  super

  if Semantic::Version.new(Middleman::VERSION).major <= 3
    app.send :include, InstanceMethods
  end

  if !options.cache_key
    raise "Please supply a cache_key value"
  end

  @copy_from_cache = []
  @add_to_cache = []
  @cache = nil
end

Instance Attribute Details

#add_to_cacheObject (readonly)

Returns the value of attribute add_to_cache.



37
38
39
# File 'lib/middleman/caching_proxy/extension.rb', line 37

def add_to_cache
  @add_to_cache
end

#copy_from_cacheObject (readonly)

Returns the value of attribute copy_from_cache.



36
37
38
# File 'lib/middleman/caching_proxy/extension.rb', line 36

def copy_from_cache
  @copy_from_cache
end

Instance Method Details

#add(item) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/middleman/caching_proxy/extension.rb', line 64

def add(item)
  if cache.has?(item)
    copy_from_cache << item
    true
  else
    add_to_cache << item
    false
  end
end

#after_build(_builder) ⇒ Object



59
60
61
62
# File 'lib/middleman/caching_proxy/extension.rb', line 59

def after_build(_builder)
  copy_new_files_to_cache
  cache.save
end

#manipulate_resource_list(resources) ⇒ Object



55
56
57
# File 'lib/middleman/caching_proxy/extension.rb', line 55

def manipulate_resource_list(resources)
  resources + cached_resources
end