Class: Rack::PageSpeed::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/pagespeed/config.rb

Defined Under Namespace

Classes: NoSuchFilter, NoSuchStorageMechanism

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
# File 'lib/rack/pagespeed/config.rb', line 8

def initialize options = {}, &block
  @filters, @options, @app = [], options, options[:app]
  filters_to_methods
  enable_filters_from_options
  enable_store_from_options
  instance_eval &block if block_given?
  sort_filters
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(filter, *args) ⇒ Object

Raises:



31
32
33
# File 'lib/rack/pagespeed/config.rb', line 31

def method_missing filter, *args
  raise NoSuchFilter, "No such filter \"#{filter}\". Available filters: #{(Rack::PageSpeed::Filter.available_filters).join(', ')}"
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/rack/pagespeed/config.rb', line 6

def app
  @app
end

#filtersObject (readonly)

Returns the value of attribute filters.



6
7
8
# File 'lib/rack/pagespeed/config.rb', line 6

def filters
  @filters
end

Instance Method Details

#store(type = nil, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/pagespeed/config.rb', line 17

def store type = nil, *args
  return @store unless type
  case type
  when {}
    @store = {} # simple in-memory store      
  when Symbol
    @store = load_storage type, *args
  when Hash
    store *type.to_a.first
  else
    raise NoSuchStorageMechanism, "No such storage mechanism: #{type}"
  end
end