Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/protector/adapters/active_record/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ module Association

# AR 4 has renamed `scoped` to `scope`
if method_defined?(:scope)
alias_method_chain :scope, :protector
alias_method :scope_without_protector, :scope
alias_method :scope, :scope_with_protector
else
alias_method 'scope_without_protector', 'scoped'
alias_method 'scoped', 'scope_with_protector'
end

alias_method_chain :build_record, :protector
alias_method :build_record_without_protector, :build_record
alias_method :build_record, :build_record_with_protector
end

# Wraps every association with current subject
Expand Down
5 changes: 3 additions & 2 deletions lib/protector/adapters/active_record/preloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module Preloader extend ActiveSupport::Concern
module Association extend ActiveSupport::Concern
included do
# AR 4 has renamed `scoped` to `scope`
if method_defined?(:scope)
alias_method_chain :scope, :protector
if method_defined?(:scope) || private_method_defined?(:scope)
alias_method :scope_without_protector, :scope
alias_method :scope, :scope_with_protector
else
alias_method 'scope_without_protector', 'scoped'
alias_method 'scoped', 'scope_with_protector'
Expand Down
15 changes: 11 additions & 4 deletions lib/protector/adapters/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ module Relation
included do
include Protector::DSL::Base

alias_method_chain :exec_queries, :protector
alias_method_chain :new, :protector
alias_method_chain :create, :protector
alias_method_chain :create!, :protector
alias_method :exec_queries_without_protector, :exec_queries
alias_method :exec_queries, :exec_queries_with_protector

alias_method :new_without_protector, :new
alias_method :new, :new_with_protector

alias_method :create_without_protector, :create
alias_method :create, :create_with_protector

alias_method :create_without_protector!, :create!
alias_method :create!, :create_with_protector!

# AR 3.2 workaround. Come on, guys... SQL parsing :(
unless method_defined?(:references_values)
Expand Down
3 changes: 2 additions & 1 deletion lib/protector/adapters/active_record/singular_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module SingularAssociation
extend ActiveSupport::Concern

included do
alias_method_chain :reader, :protector
alias_method :reader_without_protector, :reader
alias_method :reader, :reader_with_protector
end

# Reader has to be explicitly overrided for cases when the
Expand Down
3 changes: 2 additions & 1 deletion lib/protector/adapters/sequel/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def call(entity)
included do |klass|
include Protector::DSL::Base

alias_method_chain :each, :protector
alias_method :each_without_protector, :each
alias_method :each, :each_with_protector
end

def creatable?
Expand Down
3 changes: 2 additions & 1 deletion lib/protector/adapters/sequel/eager_graph_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Sequel
module EagerGraphLoader extend ActiveSupport::Concern

included do
alias_method_chain :initialize, :protector
alias_method :initialize_without_protector, :initialize
alias_method :initialize, :initialize_with_protector
end

def initialize_with_protector(dataset)
Expand Down
2 changes: 1 addition & 1 deletion lib/protector/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Protector
# Gem version
VERSION = '0.7.7'
VERSION = '0.7.8'
end