class Book < ApplicationRecord
scope :costs_more_than, ->(amount) { where("price > ?", amount) }
end
class Test < ActiveRecord::Model
scope :complicated, ComplicatedScope
class ComplicatedScope
def self.call(*args) # in new syntax use (...)
new(*args).call
end
def initialize(arg_1) # provide scope arguments
@arg_1 = arg_1
end
def call
module_parent
.joins("complicated JOIN querry")
.where("complicated where ?", @arg_1)
.merge("some merging")
end
delegate :module_parent, to: :class
end
end
Test.complcated("arg_1")
scope :proponent, ->(user){ where(user_id: user.id) }