Make the strainer monkey patch more conservative and compatible
This commit is contained in:
parent
3c9e9764b0
commit
a0a2776f95
|
@ -19,20 +19,22 @@ module ChiliProject
|
||||||
module Strainer
|
module Strainer
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.extend(ClassMethods)
|
base.extend(ClassMethods)
|
||||||
base.class_eval do
|
|
||||||
@@filters = []
|
base.class_attribute :filters, :instance_reader => false, :instance_writer => false
|
||||||
end
|
base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||||
|
self.filters = @@filters.values
|
||||||
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def global_filter(filter)
|
def global_filter(filter)
|
||||||
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
||||||
@@filters << filter
|
filters += [filter]
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(context)
|
def create(context)
|
||||||
strainer = self.new(context)
|
strainer = self.new(context)
|
||||||
@@filters.each { |filter| strainer.extend(filter) }
|
filters.each { |filter| strainer.extend(filter) }
|
||||||
strainer
|
strainer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue