Module: CampingFilters

Defined in:
lib/bivouac/ext/filtering_camping.rb

Overview

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



25
26
27
# File 'lib/bivouac/ext/filtering_camping.rb', line 25

def self.included(mod)
  mod.extend(ClassMethods)
end

Instance Method Details

#run_filters(type) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/bivouac/ext/filtering_camping.rb', line 29

def run_filters(type)
  o = self.class.to_s.split("::")
  filters = Object.const_get(o.first).filters
  filters[type].each do |filter|
    if (filter[0].is_a?(Symbol) && (filter[0] == o.last.to_sym || filter[0] == :all)) ||
       (filter[0].is_a?(String) && /^#{filter[0]}\/?$/ =~ @env.REQUEST_URI)
       self.instance_eval(&filter[1])
    end
  end
end

#service(*a) ⇒ Object



40
41
42
43
44
45
# File 'lib/bivouac/ext/filtering_camping.rb', line 40

def service(*a)
  run_filters(:before)
  ret = super(*a)
  run_filters(:after)
  self
end