Sha256: a1d05b7898b1f52d9252dbbba33fa444d4cc50f5f89361a6dd184e0ef0f58c46

Contents?: true

Size: 829 Bytes

Versions: 3

Compression:

Stored size: 829 Bytes

Contents

module KirguduBase
	module Concerns::Models::UserId
		extend ActiveSupport::Concern

		included do
			before_query :query_add_user_id

			belongs_to :user, class_name: ::KirguduBase::Security::User, foreign_key: :user_id
			scope :by_user_id, lambda { |value| where(user_id: value) if value }
			scope :with_user_keyword, lambda { |value|
				like_value = "%#{value.gsub('%', ' ').strip}%" rescue nil
				where { (user.last_name.like like_value) | (user.first_name.like like_value) } if like_value

			}
		end


		def user_name
			self.user.full_name if self.user
		end

		############################ CLASS METHODS ###############################
		module ClassMethods
			def query_add_user_id(query, filters)
				query
				.by_user_id(filters[:user_id])
				.with_user_keyword(filters[:user_keyword])

			end
		end

	end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kirgudu_base-0.0.25 app/models/kirgudu_base/concerns/models/user_id.rb
kirgudu_base-0.0.23 app/models/kirgudu_base/concerns/models/user_id.rb
kirgudu_base-0.0.22 app/models/kirgudu_base/concerns/models/user_id.rb