-
-
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
Changes from 29 commits
6d7ddae
567f867
8cd67ca
17d5ed2
9aeaa2d
dac0b19
dbac159
a89b21f
fa4c678
1f5aedc
51bd155
f529ad0
0e2ed61
49f5df6
dbf1807
83cdf79
674aa88
3392191
58e81c2
0dc8572
516053b
8036261
2ddb04c
c7d238b
1093911
e4e0802
49c24b5
56fd879
88d9af1
5eb3e6e
ec8f582
27e688a
1d458aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module ActiveRecord::Acts::List::SequentialUpdatesDefiner #:nodoc: | ||
def self.call(caller_class, column, sequential_updates_option) | ||
caller_class.class_eval do | ||
@sequential_updates = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems unintuitive to set a variable at this point. Perhaps set it within @sequential_updates = nil unless defined?(@sequential_updates) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, removed class-level initializer. |
||
|
||
define_method :sequential_updates? do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
caller_class.class_eval do
private
def sequential_updates?
...
end
end
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
if @sequential_updates.nil? | ||
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 |
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.
Just realised that this class name doesn't match the file name. Can you change the class name as all the other definer classes are
...MethodDefiner
:)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, that eagle eye) Fixed.