module FindOrBuildable
  extend ActiveSupport::Concern

  included do
    after_initialize do
      self.class.reflect_on_all_associations(:has_one).each do |association|
        self.class.define_method("find_or_build_#{association.name}") do
          send(association.name) || send("build_#{association.name}")
        end
      end
    end
  end
end
