Extract the scope building to a class method
This commit is contained in:
parent
1a30b1ed40
commit
c1cd342456
@ -42,14 +42,29 @@ def self.create_builder(model, name, scope, options, extension = nil)
|
||||
|
||||
def initialize(name, scope, options, extension)
|
||||
@name = name
|
||||
@scope = scope
|
||||
@options = options
|
||||
|
||||
self.class.validate_options(options)
|
||||
|
||||
@scope = self.class.build_scope(scope, extension)
|
||||
end
|
||||
|
||||
def self.build_scope(scope, extension)
|
||||
new_scope = scope
|
||||
|
||||
if scope && scope.arity == 0
|
||||
@scope = proc { instance_exec(&scope) }
|
||||
new_scope = proc { instance_exec(&scope) }
|
||||
end
|
||||
|
||||
if extension
|
||||
new_scope = wrap_scope new_scope, extension
|
||||
end
|
||||
|
||||
new_scope
|
||||
end
|
||||
|
||||
def self.wrap_scope(scope, extension)
|
||||
scope
|
||||
end
|
||||
|
||||
def build(model)
|
||||
|
@ -12,14 +12,6 @@ def self.valid_options(options)
|
||||
:after_add, :before_remove, :after_remove, :extend]
|
||||
end
|
||||
|
||||
def initialize(name, scope, options, extension)
|
||||
super
|
||||
|
||||
if extension
|
||||
@scope = self.class.wrap_scope @scope, extension
|
||||
end
|
||||
end
|
||||
|
||||
def self.define_callbacks(model, reflection)
|
||||
super
|
||||
name = reflection.name
|
||||
|
Loading…
Reference in New Issue
Block a user