Skip to content
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

Refactor class_eval with string into class_eval with block #215

Merged
merged 6 commits into from
Aug 28, 2016

Conversation

rdvdijk
Copy link
Contributor

@rdvdijk rdvdijk commented Aug 10, 2016

This commit changes the "class_eval with string"-style to "class_eval with block"-style.

The only worry I have is the remaining string eval in the method definition on line 96:

              define_method :scope_condition do
                eval "%{#{configuration[:scope]}}"
              end

Of course this eval happens in the current code, but just isn't that obvious as it is now.

Added bonus is that the position column is now quoted lazily, removing the need of an established database connection at model load-time, as mentioned in #214.

(Now let's see if all supported Ruby versions agree with this, Travis will let us know soon 😉)

@rdvdijk
Copy link
Contributor Author

rdvdijk commented Aug 10, 2016

Travis build fails because:

  1. github_changelog_generator depends on rack, which will install the latest version 2.0.1, which in turn requires Ruby >= 2.2.2
  2. acts_as_list depends on activerecord >= 3.0, which will install the latest version 5.0.0, which depends on activesupport version 5.0.0, which also depends on Ruby >= 2.2.2

I can fix the first by requiring rack < 2.0 in the Gemfile, but what about the second problem?.

(Nevermind the second point, just noticed the use of appraisal.)

EDIT: I've proposed a fix to the Travis build in #216

@brendon
Copy link
Owner

brendon commented Aug 10, 2016

Thanks for this @rdvdijk. Let's take a look at this once we've sorted out the rack problem :)

@brendon
Copy link
Owner

brendon commented Aug 11, 2016

Hi @rdvdijk, can you rebase this to master (I've fixed the tests), and see how the suite runs?

@rdvdijk rdvdijk force-pushed the refactor_class_eval branch from f265298 to 11020f4 Compare August 11, 2016 07:21
@rdvdijk
Copy link
Contributor Author

rdvdijk commented Aug 11, 2016

@brendon Rebased. I left the tab-to-spaces fix in the Gemfile 😉

Thanks for improving upon my appraisals/rack PR.

@brendon
Copy link
Owner

brendon commented Aug 11, 2016

Thanks @rdvdijk :) All seems to have passed.

@swanandp, @fabn, and @krzysiek1507 did you want to have any input into this one?

def scope_condition
{ #{configuration[:scope]}: send(:#{configuration[:scope]}) }
end
class_calling_acts_as_list = self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow this name doesn't sound good. Maybe caller_class ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe caller_class ?

Sounds good. I'll change it.

@swanandp
Copy link
Contributor

Good stuff! Just left a minor comment.

@brendon
Copy link
Owner

brendon commented Aug 18, 2016

Ok, once that's fixed, I'll merge this one.

@brendon
Copy link
Owner

brendon commented Aug 18, 2016

Oh, also needs rebasing :)

@rdvdijk
Copy link
Contributor Author

rdvdijk commented Aug 26, 2016

Ah, feedback! I've been away on holiday, I'll take a look at the comments soon. And do another rebase. 😄

@rdvdijk rdvdijk force-pushed the refactor_class_eval branch from 11020f4 to 57923ee Compare August 26, 2016 19:51
@rdvdijk
Copy link
Contributor Author

rdvdijk commented Aug 26, 2016

@brendon I've fixed the variable name and rebased.

The quoted_position_column_with_table_name change made the rebase a little challenging, but I think all is well now. (I did notice that that there were no explicit tests for that particular feature...)

@brendon
Copy link
Owner

brendon commented Aug 28, 2016

Thanks @rdvdijk, I think the reason why there were no explicit tests was that it was just a refactor of existing code, though for sure, they could have attempted to test for their obscure failure case. I might ping them on that. I'm happy to merge this now. Thank you for all your hard work on this.

@brendon brendon merged commit a5fc7cf into brendon:master Aug 28, 2016
@rdvdijk
Copy link
Contributor Author

rdvdijk commented Aug 29, 2016

Awesome, thanks!

About my initial comment about the remaining string-eval in scope condition: it might be time to deprecate unsafe code like that. I think the "symbol" way of providing a scope condition should suffice in all use cases. Or are there use cases that I'm just not seeing here?

@brendon
Copy link
Owner

brendon commented Aug 29, 2016

Let's open this up in a new issue. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants