Interesting: Is this additional logic necessary?
If the method saveon each of yours @subservicesobeys ActiveRecord semantics save, you are likely to get the right behavior for free.
In other words, be sure that the methods savereturn trueeither falsefor success or failure. Then the composite code becomes so simple:
class CompositeService < Service
attr_accessible :subservices
before_save :save_subservices
private
def save_subservices
@subservices.all?(&:save)
end
end
- , save_subservices false, . save save. save! .
composite.save
# => false
composite.save!
# => ActiveRecord::RecordNotSaved