-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
insert_at respects unique not null check (>= 0) db constraints #246
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
6d7ddae
insert_at respects unique not null check (>= 0) constraints
zharikovpro 567f867
killed orphaned function store_at_0 (was invented earlier by someone …
zharikovpro 8cd67ca
wip: tests
zharikovpro 17d5ed2
green tests
zharikovpro 9aeaa2d
one red test
zharikovpro dac0b19
green tests for sequential increments
zharikovpro dbac159
SQLite and PostgreSQL tests green
zharikovpro a89b21f
better test
zharikovpro fa4c678
green tests for SQLite and PostgreSQL for DefaultScopedNotNullUniqueP…
zharikovpro 1f5aedc
work in progress: some appraisals fixes
zharikovpro 51bd155
Revert "work in progress: some appraisals fixes"
zharikovpro f529ad0
tests: add_index compatible with rails 3-2
zharikovpro 0e2ed61
tests: rails 3-2 doesnt have .ids method for AR
zharikovpro 49f5df6
Rakefile restored (corrupted by accident, sorry)
zharikovpro dbf1807
DefaultScopedNotNullUniquePositiveConstraintsTest compatible with Rai…
zharikovpro 83cdf79
better test index name
zharikovpro 674aa88
code review for shuffle_positions_on_intermediate_items - no unscope,…
zharikovpro 3392191
sequential_update option for shuffle_positions_on_intermediate_items
zharikovpro 58e81c2
sequential_updates configuration option description
zharikovpro 0dc8572
wip: green tests for sequential_updates defaults, red NoAdditionMixin…
zharikovpro 516053b
green tests with SequentialUpdatesDefault mixin and SequentialUpdates…
zharikovpro 8036261
sequential_updates default value detection shouldn't throw exception …
zharikovpro 2ddb04c
file rename
zharikovpro c7d238b
renamed var
zharikovpro 1093911
made shuffle_positions_on_intermediate_items private again
zharikovpro e4e0802
green local tests for SequentialUpdatesDefiner with instance level la…
zharikovpro 49c24b5
SequentialUpdatesDefiner readability refactoring
zharikovpro 56fd879
Merge with origin repo's master
zharikovpro 88d9af1
removed redundant require
zharikovpro 5eb3e6e
review code style tweak
zharikovpro ec8f582
code shortened after review
zharikovpro 27e688a
ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner - proper cla…
zharikovpro 1d458aa
use latest stable bundler version which do not cause failed Travis bu…
zharikovpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
21 changes: 21 additions & 0 deletions
21
lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
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,21 @@ | ||
module ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner #:nodoc: | ||
def self.call(caller_class, column, sequential_updates_option) | ||
caller_class.class_eval do | ||
define_method :sequential_updates? do | ||
if !defined?(@sequential_updates) | ||
if sequential_updates_option.nil? | ||
table_exists = caller_class.connection.table_exists?(caller_class.table_name) | ||
index_exists = caller_class.connection.index_exists?(caller_class.table_name, column, unique: true) | ||
@sequential_updates = table_exists && index_exists | ||
else | ||
@sequential_updates = sequential_updates_option | ||
end | ||
else | ||
@sequential_updates | ||
end | ||
end | ||
|
||
private :sequential_updates? | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class_eval
allows us to just write normal Ruby to be executed within the scope of the class. So you can just dodefine_method
is primarily used to define a method with a string interpolated variable name as far as I've seen it. Give it a go and let me know if it doesn't work as expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, calling sequential_updates? that way will produce 'undefined local variable or method `sequential_updates_option'. Cause, well, sequential_updates_option would be really not a local variable nor method (undefined). This definer trick makes it available for the sequential_updates? block, cause block do have access to the caller scope variables.
Another possible option is to store the whole acts_as_list configuration as a class variable after initialization. But this is not in the style of this gem.
Please check a perfect example of doing the same thing inside another definer. It defines method which implementation relies on config option. I do it the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see :) Sorry about that :) I was focused on the instance variable and didn't realise you were talking about the incoming config :) I agree, no class variables is definitely preferred.