Reputation: 2125
I've small problem with organizing some resources in my Rails app. Let's say:
# app/models/bucket.rb
class Bucket < ActiveRecord::Base
end
I would like to add simple class to make some calculations over Bucket
let's say:
class ItemsCalculator
end
and...
class ShippingCostCalculator
end
How I'm supposed to organize these 3 classes having in mind logically relation with Bucket
.
I've a couple of options:
1)
app/models/bucket -> Bucket
app/models/bucket/items_calculator -> Bucket::ItemsCalculator
app/models/bucket/shipping_cost_calculator -> Bucket::ShippingCostCalculator
2)
app/models/bucket -> Bucket
lib/bucket/items_calculator -> ItemsCalculator
lib/bucket/shipping_cost_calculator -> ShippingCostCalculator
3)
app/models/bucket -> Bucket
lib/bucket/items_calculator -> Bucket::ItemsCalculator
lib/bucket/items_calculator -> Bucket::ShipingCalculator
What do you prefer, which version is most proper ?
Upvotes: 0
Views: 73
Reputation: 187262
Models are what should handle the business logic of your application. Models do not need to inherit from ActiveRecord::Base
to be a model. So these calculator classes sound like models to me.
So my opinion is that they go in app/models
. But are they applicable in any general way? Or do they only apply to Bucket
? If they only apply to Bucket
then option 1 makes sense.
But if they apply to other models, or can be used standalone, I might recommend:
app/models/bucket -> Bucket
app/models/items_calculator -> ItemsCalculator
app/models/shipping_cost_calculator -> ShippingCostCalculator
But my hunch is that you want option 1.
Upvotes: 2