Sha256: 6ca8bf2a0712337d0ce58dadfb6f66bd54b7062b8d8852c812e17f3890f2c705

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

require 'hobo_fields'

module GitModels
  module User
    extend ActiveSupport::Concern

    included do
      fields do
        name :text, limit: 255, null: false
        email :text, limit: 255, null: false
        timestamps
      end

      validates :name, uniqueness: { scope: :email }

      has_many :branches, class_name: 'Branch', foreign_key: 'author_id'
      has_many :commits, class_name: 'Commit', foreign_key: 'author_id'
    end

    class_methods do
      def create_from_git_data!(branch_data)
        where(name: branch_data.author_name, email: branch_data.author_email).first_or_create!
      end

      def users_with_emails(email_filter_list)
        # if filter is empty, return all users, otherwise only return users whose emails are in the list
        all.select { |user| email_filter_list.empty? || email_filter_list.include?(user.email.downcase) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_models-1.2.0 app/models/concerns/user.rb