Module: Rango::FiltersMixin::ClassMethods

Defined in:
lib/rango/mixins/filters.rb

Instance Method Summary collapse

Instance Method Details

#after(action = nil, options = Hash.new, &block) ⇒ Object

Since:

  • 0.0.2



64
65
66
# File 'lib/rango/mixins/filters.rb', line 64

def after(action = nil, options = Hash.new, &block)
  self.after_filters[action || block] = options
end

#after_filtersObject

Since:

  • 0.2



52
53
54
# File 'lib/rango/mixins/filters.rb', line 52

def after_filters
  @after_filters ||= Hash.new
end

#before(action = nil, options = Hash.new, &block) ⇒ Object

before :login before :login, except: [:send]

Since:

  • 0.0.2



59
60
61
# File 'lib/rango/mixins/filters.rb', line 59

def before(action = nil, options = Hash.new, &block)
  self.before_filters[action || block] = options
end

#before_filtersObject

we can’t use class variables because they are shared between parent and child classes

Since:

  • 0.2



47
48
49
# File 'lib/rango/mixins/filters.rb', line 47

def before_filters
  @before_filters ||= Hash.new
end

#get_filters(type) ⇒ Object

Since:

  • 0.0.2



69
70
71
# File 'lib/rango/mixins/filters.rb', line 69

def get_filters(type)
  self.send("#{type}_filters")
end

#inherited(subclass) ⇒ Object

If you are using your own inherited hook, you have to use super here, otherwise your filters won’t work!



38
39
40
41
42
# File 'lib/rango/mixins/filters.rb', line 38

def inherited(subclass)
  subclass.before_filters.replace(self.before_filters)
  subclass.after_filters.replace(self.after_filters)
  super
end