-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acts_as_list_no_update for disabling callbacks (#244)
- Loading branch information
Showing
11 changed files
with
192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
require "acts_as_list/active_record/acts/list" | ||
require 'acts_as_list/active_record/acts/list' | ||
require "acts_as_list/active_record/acts/column_method_definer" | ||
require "acts_as_list/active_record/acts/scope_method_definer" | ||
require "acts_as_list/active_record/acts/top_of_list_method_definer" | ||
require "acts_as_list/active_record/acts/add_new_at_method_definer" | ||
require "acts_as_list/active_record/acts/aux_method_definer" | ||
require "acts_as_list/active_record/acts/callback_definer" | ||
require 'acts_as_list/active_record/acts/no_update' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module ActiveRecord | ||
module Acts | ||
module List | ||
module NoUpdate | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
# Lets you selectively disable all act_as_list database updates | ||
# for the duration of a block. | ||
# | ||
# ==== Examples | ||
# ActiveRecord::Acts::List.acts_as_list_no_update do | ||
# TodoList.... | ||
# end | ||
# | ||
# TodoList.acts_as_list_no_update do | ||
# TodoList.... | ||
# end | ||
# | ||
def acts_as_list_no_update(&block) | ||
NoUpdate.apply_to(self, &block) | ||
end | ||
end | ||
|
||
class << self | ||
def apply_to(klass) | ||
klasses.push(klass) | ||
yield | ||
ensure | ||
klasses.pop | ||
end | ||
|
||
def applied_to?(klass) | ||
klasses.any? { |k| k >= klass } | ||
end | ||
|
||
private | ||
|
||
def klasses | ||
Thread.current[:act_as_list_no_update] ||= [] | ||
end | ||
end | ||
|
||
def act_as_list_no_update? | ||
NoUpdate.applied_to?(self.class) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.