Module: TinyFilter::Concern

Defined in:
lib/tiny_filter/concern.rb

Class Method Summary collapse

Class Method Details

.included(other) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tiny_filter/concern.rb', line 6

def included(other)
  if defined?(ActiveRecord::Base) && other <= ActiveRecord::Base
    other.scope :filter_by, ->(args = {}) { TinyFilter::FilterFinder.find(self).filter(self, args) }
  elsif defined?(Sequel::Model) && other <= Sequel::Model
    other.dataset_module do
      def filter_by(args = {})
        TinyFilter::FilterFinder.find(self).filter(self, args)
      end
    end
  else
    raise Error, "unable to include TinyFilter::Concern in #{other} " \
      "that is not an ActiveRecord::Base or Sequel::Model descendant"
  end
end