Module: Lycra::Search::Scoping::ClassMethods

Defined in:
lib/lycra/search/scoping.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/lycra/search/scoping.rb', line 113

def self.extended(base)
  # Generic Shared Scopes
  base.send :scope, :all, -> { offset(0).limit(10_000) }
  base.send :scope, :unfiltered, -> { refilter }
  base.send :scope, :unsorted, -> { resort }
  base.send :scope, :sort_by, -> (field, order=:asc) { sort({field => {order: order}}) }
  base.send :scope, :by_id, -> (*objs) {
    filter_by(:id, [objs].flatten.map { |obj| obj.respond_to?(:id) ? obj.id : obj })
  }
end

Instance Method Details

#scope(name, block) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/lycra/search/scoping.rb', line 124

def scope(name, block)
  instance_eval do
    define_method name.to_sym do |*args|
      @response = nil
      instance_exec *args, &block
      self
    end
  end
end