diff options
Diffstat (limited to 'app/services/members/standard_member_builder.rb')
-rw-r--r-- | app/services/members/standard_member_builder.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/services/members/standard_member_builder.rb b/app/services/members/standard_member_builder.rb new file mode 100644 index 00000000000..24e71f80d7e --- /dev/null +++ b/app/services/members/standard_member_builder.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Members + class StandardMemberBuilder + def initialize(source, invitee, existing_members) + @source = source + @invitee = invitee + @existing_members = existing_members + end + + def execute + find_or_initialize_member_by_user(invitee.id) + end + + private + + attr_reader :source, :invitee, :existing_members + + def find_or_initialize_member_by_user(user_id) + existing_members[user_id] || source.members_and_requesters.build(user_id: user_id) # rubocop:disable CodeReuse/ActiveRecord + end + end +end |