Sha256: db8f9ff0e61fc17f7db543a1893fbedda012769a5bfcb76b1e54187d1bb880ba
Contents?: true
Size: 950 Bytes
Versions: 10
Compression:
Stored size: 950 Bytes
Contents
module ActiveRecord module Scoping module Named module ClassMethods attr_reader :scope_names def scope(name, body, &block) @scope_names ||= [] unless body.respond_to?(:call) raise ArgumentError, 'The scope body needs to be callable.' end if dangerous_class_method?(name) raise ArgumentError, "You tried to define a scope named \"#{name}\" " \ "on the model \"#{self.name}\", but Active Record already defined " \ "a class method with the same name." end extension = Module.new(&block) if block singleton_class.send(:define_method, name) do |*args| scope = all.scoping { body.call(*args) } scope = scope.extending(extension) if extension scope || all end @scope_names << name if body.arity.eql?(0) end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems