added 260907 version of worker toolkit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
module Authenticatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
#
|
||||
# Devise
|
||||
#
|
||||
devise :database_authenticatable,
|
||||
:rememberable,
|
||||
:recoverable,
|
||||
:trackable,
|
||||
:validatable,
|
||||
:invitable,
|
||||
:omniauthable
|
||||
|
||||
#
|
||||
# Validates
|
||||
#
|
||||
validates :password, confirmation: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
module Topicable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
TOPIC_TYPES = %w[tag symptom condition treatment].freeze
|
||||
|
||||
included do
|
||||
field :tag_ids, type: Array, default: []
|
||||
field :symptom_ids, type: Array, default: []
|
||||
field :condition_ids, type: Array, default: []
|
||||
field :treatment_ids, type: Array, default: []
|
||||
|
||||
field :encrypted_user_id, type: String, encrypted: {type: :integer}
|
||||
|
||||
validates :encrypted_user_id, presence: true
|
||||
|
||||
TOPIC_TYPES.each do |relative|
|
||||
pluralized_relative = relative.pluralize
|
||||
|
||||
define_method(:"#{pluralized_relative}") do
|
||||
ivar_name = :"@_#{pluralized_relative}"
|
||||
|
||||
value = instance_variable_get(ivar_name)
|
||||
|
||||
return value if value.present?
|
||||
|
||||
value = instance_variable_set(ivar_name, relative.classify.constantize.where(id: send("#{relative}_ids")))
|
||||
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
module Usernameable
|
||||
def user_name
|
||||
Profile.select(:screen_name).find_by!(user_id: SymmetricEncryption.decrypt(encrypted_user_id)).screen_name
|
||||
rescue SymmetricEncryption::CipherError
|
||||
""
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user