-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Misc touchups #150
Misc touchups #150
Changes from all commits
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ pkg/* | |
|
||
Gemfile.lock | ||
*.gemfile.lock | ||
|
||
spec/examples.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ class NonNilColumnDefault < StandardError; end | |
MIN_RANK_VALUE = -2147483648 | ||
|
||
def self.included base | ||
super | ||
|
||
base.class_eval do | ||
class_attribute :rankers | ||
|
@@ -42,6 +43,10 @@ def ranker name | |
end | ||
end | ||
|
||
def ranker_connection_class | ||
ActiveRecord::Base | ||
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. We explicitly rely on ActiveRecord so why do we need to abstract this? :) 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. for application with multiple databases it's nice to be able to specify the connection class. ideally really it would just be the current active record class which would always do the right thing due to the way the connection handler threading is handled, but having a way to easily specify the connection class is probably best in both cases 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. We may not need this per my other comment below. |
||
end | ||
|
||
private | ||
|
||
def ranks *args | ||
|
@@ -69,7 +74,7 @@ def ranks *args | |
end | ||
|
||
def column_default ranker | ||
column_defaults[ranker.name.to_s] if ActiveRecord::Base.connected? | ||
column_defaults[ranker.name.to_s] if ranker_connection_class.connected? | ||
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. Would it work if we just called 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. on the right receiver, yeah.. rails connection handlers are per thread class attributes |
||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
module RankedModel | ||
|
||
class Railtie < Rails::Railtie | ||
|
||
initializer "ranked-model.initialize" do |app| | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ def assure_unique_position | |
|
||
def rearrange_ranks | ||
_scope = finder | ||
escaped_column = ActiveRecord::Base.connection.quote_column_name ranker.column | ||
escaped_column = instance_class.ranker_connection_class.connection.quote_column_name ranker.column | ||
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. This call becomes quite clunky with the abstraction. 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 should probably just be instance_class anyhow 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. Agreed. Let's go with that. Especially given a particular model may have a different connection. |
||
# If there is room at the bottom of the list and we're added to the very top of the list... | ||
if current_first.rank && current_first.rank > RankedModel::MIN_RANK_VALUE && rank == RankedModel::MAX_RANK_VALUE | ||
# ...then move everyone else down 1 to make room for us at the 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.
this is really a good idea to have. oh well
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.
I'm unfamiliar with this technique. Can you link me to something that explains why it's necessary or nice to have?
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.
I mean, it may be unexpected but it makes sense, too. It's just Ruby
prints
while
prints
and
prints
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.
Your examples are around
self.inherited
but this method isself.included
. Am I missing something? :)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.
So to clarify, this is just in case someone chooses to extend this module for some reason? :)
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.
Hehe, that's what I was thinking. Not sure why anyone would want to extend RankedModel. And is it possible to extend a module?
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.
you can include or prepend a module into a module. I started to write an example but it worked in your favor in this context :) the only way to inherit a module is by fooling Ruby because Module is a class
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.
Lol, I'm glad we've managed to nut this one out :) So I guess remove this line from the PR?
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.
I guess there's rubocop/ruby-style-guide#809 rubocop/rubocop#8376 rubocop/rubocop@9d5cbe6
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.
Yep sounds like they don't raise anything on module
included
based on my quick skim of that code. I assume that's what you were saying?Are you happy to remove this and also look at calling
connection
directly on the class per our discussions below and see how it tests out?