unknown wrote in post #1116591:
> I think I might be a little confused but I cant really understand
> exactly
> when to separate code into a concern, and when to separate it into a
> library.
>
> 1. What's the exact difference?
Concerns is a technique used to either share some behavior between
models or to break down "chubby" models into smaller, more coherent
pieces. Notice this is all about model objects.
Library code on the other hand should be self contained, independent
behaviors that can be use anywhere.
> 2. Where are they available?
Model Concerns: Any model object where you choose to include them.
Notice that concerns "extend ActiveSupport::Concern" and therefore have
that direct dependency.
Controller Concerns: Similar to the model concerns except for
controllers.
Library: Should have no direct dependencies outside of itself (other
than libraries a library directly depends upon. i.e Rails itself has
many dependencies managed by RubyGems).
You should (in theory) be able to include a library anywhere, even in
apps that don't use Rails at all. Notice that many gems (libraries) are
useful no matter what framework you use them with. You could have a
Sinatra app and include the same gem as in a Rails app. There's no
direct dependency there.
> 3. What is their goal? what is the goal of putting code in a concern and
> in
> a library?
This explains concerns pretty well I think:
http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns
--
Posted via
http://www.ruby-forum.com/.