Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Applying Clean Architecture: Repository
module Repositories
class BusinessProfiles
def find business_id
data_model = ::BusinessProfile.find_by business_id: business_id
if data_model
fields = fields_for data_model
profile = Nav::Entities::BusinessProfile.new data_model.business_id
fields.each { |name, value| profile.send(:"#{name}=", value) }
else
profile = Nav::Entities::BusinessProfile.new 0
profile.errors << "can not find Business Profile with ID #{business_id}"
end
profile
end
def update for_id:, fields: {}
ActiveRecord::Base.transaction do
profile = BusinessProfile.find_or_create_by! business_id: for_id
fields.each do |name, value|
Field.create! business_profile: profile,
name: name,
value: value,
reported_at: DateTime.now
end
end
find for_id
end
private
def fields_for data_model
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.