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.

Raises:

  • (ArgumentError)


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

def initialize options = {}, &block
  @filters, @options, @public = [], options, options[:public]
  raise ArgumentError, ":public needs to be a directory" unless File.directory? @public.to_s
  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:



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

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

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



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

def filters
  @filters
end

#publicObject (readonly)

Returns the value of attribute public.



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

def public
  @public
end

Instance Method Details

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



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

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