Skip to content

Add No Touching#12772

Merged
rafaelfranca merged 1 commit intorails:masterfrom
dmathieu:no_touching
Nov 13, 2013
Merged

Add No Touching#12772
rafaelfranca merged 1 commit intorails:masterfrom
dmathieu:no_touching

Conversation

@dmathieu
Copy link
Copy Markdown
Contributor

@dmathieu dmathieu commented Nov 5, 2013

This adds #no_touching on all ActiveRecord models, allowing to ignore touching for the duration of a block.

Example:

ActiveRecord::Base.no_touching do
  Post.first.touch #=> Does nothing
end

Comment.no_touching do
  Comment.first.touch #=> Does nothing
  Post.first.touch #=> Updates, but won't update related comments if there are any
end

cc @dhh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is not this inside the ClassMethods module?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I put them in the ClassMethods module, I can't access them through NoTouching.apply_to, like we do at line 22.
And it means the model gets the apply_to and applied_to? methods, while here, they're only in the module.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, right. Please put # :nodoc: in the methods

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! 🌞

@egilburg
Copy link
Copy Markdown
Contributor

egilburg commented Nov 5, 2013

I think without_touch or 'without_touching` sounds better.

@dhh
Copy link
Copy Markdown
Member

dhh commented Nov 5, 2013

I like the fun of no_touching.

On Nov 5, 2013, at 8:33, Eugene Gilburg notifications@github.com wrote:

I think without_touch or 'without_touching` sounds better.


Reply to this email directly or view it on GitHub.

@sausman
Copy link
Copy Markdown

sausman commented Nov 5, 2013

I like the sound of no_touch.

@nijikon
Copy link
Copy Markdown

nijikon commented Nov 5, 2013

+1 for no_touch

@mbhnyc
Copy link
Copy Markdown
Contributor

mbhnyc commented Nov 6, 2013

no_touchy_touchy maximizes fun, while also maximizing awkwardness!

@dmathieu
Copy link
Copy Markdown
Contributor Author

dmathieu commented Nov 6, 2013

From experience the "fun" things in rails don't stick around (I'm thinking of the snowman for example).
So I renamed it to no_touch in my pull request.

@nijikon
Copy link
Copy Markdown

nijikon commented Nov 6, 2013

👍

@dhh
Copy link
Copy Markdown
Member

dhh commented Nov 6, 2013

Eh, what? Look up #forty_two. Do rename it back.

On Nov 6, 2013, at 16:59, Damien Mathieu notifications@github.com wrote:

From experience the "fun" things in rails don't stick around (I'm thinking of the snowman for example).
So I renamed it to no_touch in my pull request.


Reply to this email directly or view it on GitHub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code is not thread safe. We need to store in a thread local variable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've fixed the thread safe problem.

@dhh
Copy link
Copy Markdown
Member

dhh commented Nov 12, 2013

Besides these few comments I just added, are we otherwise ready to merge?

@dmathieu
Copy link
Copy Markdown
Contributor Author

I just applied your two comments. :shipit:

rafaelfranca added a commit that referenced this pull request Nov 13, 2013
@rafaelfranca rafaelfranca merged commit 3d2e8cb into rails:master Nov 13, 2013
@dmathieu dmathieu deleted the no_touching branch November 13, 2013 22:18
@lukaszx0
Copy link
Copy Markdown
Member

I liked @steveklabnik's idea of calling it #cant_touch_this the most 🤘

@guilleiguaran
Copy link
Copy Markdown
Member

LOL :trollface:

Sent from my iPhone

On 20 Nov 2013, at 09:02 pm, Łukasz Strzałkowski notifications@github.com wrote:

I liked @steveklabnik's idea of calling it #cant_touch_this the most


Reply to this email directly or view it on GitHub.

@arenoir
Copy link
Copy Markdown

arenoir commented Apr 18, 2014

@dmathieu this is very handy, however it seems after_touch callbacks still get run. Is there a way to disable after_touch callbacks?

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.