def membership(attributes)
      if (attributes[:entry].present? && attributes[:entity].present?) ||
         (attributes[:account].present? && attributes[:entity].present?)
        say_attribute_precedence(':entity', ':entry and :account')
      end
      unless attributes[:entity].present?
        entry_or_account_attributes_specified attributes
      end

      if attributes[:entity].is_a?(Entry) || attributes[:entry].present?
        entry = attributes[:entity] || attributes[:entry]
        unless attributes[:user].accounts.include?(entry.account)
          Membership.find_or_create_by!(entity: entry.account,
                                        user: attributes[:user],
                                        role: :member) do |membership|
            say_creating_membership(membership)
          end
        end
      end

      Membership.find_or_create_by!(attributes) do |membership|
        say_creating_membership(membership)
      end
    end
def membership(attributes)
      if (attributes[:entry].present? && attributes[:entity].present?) ||
         (attributes[:account].present? && attributes[:entity].present?)
        say_attribute_precedence(':entity', ':entry and :account')
      end
      unless attributes[:entity].present?
        entry_or_account_attributes_specified attributes
      end

      if attributes[:entity].is_a?(Entry) || attributes[:entry].present?
        entry = attributes[:entity] || attributes[:entry]
        unless attributes[:user].accounts.include?(entry.account)
          Membership.find_or_create_by!(entity: entry.account,
                                        user: attributes[:user],
                                        role: :member) do |membership|
            say_creating_membership(membership)
          end
        end
      end

      Membership.find_or_create_by!(attributes) do |membership|
        say_creating_membership(membership)
      end
    end
Create a {Membership} for the given user and entity.
 Create a {Membership} for the corresponding account first if a {Membership} on an entry is to
 be created and no {Membership} on the entry's account exists yet.

 @param [Hash] attributes  attributes to override defaults
 @option attributes [User] :user  required
 @option attributes [Entity] :entity  required
 :entry and :account are lower-priority aliases for :entity
 @return [Membership] newly created membership