Class: Ish::UserProfile
- Inherits:
-
Object
- Object
- Ish::UserProfile
- Includes:
- Utils, Mongoid::Document, Mongoid::Timestamps, Mongoid::Voter
- Defined in:
- lib/ish/user_profile.rb
Overview
@TODO: rename to Ish::Profile
Constant Summary collapse
- ROLES =
[ :guy, :manager, :admin ]
- ROLE_GUY =
:guy- ROLE_MANAGER =
:manager- ROLE_ADMIN =
:admin
Class Method Summary collapse
-
.generate(delta) ⇒ Object
used in rake tasks.
-
.list ⇒ Object
manager uses it.
Instance Method Summary collapse
- #bookmarks ⇒ Object
- #export_fields ⇒ Object
- #has_premium_purchase(item) ⇒ Object
-
#n_coins ⇒ Object
@deprecated, do not use.
-
#n_stars ⇒ Object
GameUI.
- #premium_purchases ⇒ Object
- #sudoer? ⇒ Boolean
-
#videos ⇒ Object
@TODO: do something about this.
-
#videos_embed ⇒ Object
preferences @TODO: better naming convention, or remove this.
Methods included from Utils
Methods included from Mongoid::Voter
#unvote, #vote, #vote_value, #voted?, #votees
Class Method Details
.generate(delta) ⇒ Object
used in rake tasks
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ish/user_profile.rb', line 109 def self.generate delta email = delta[:email] password = delta[:password] role_name = delta[:role_name] profile = Ish::UserProfile.where( email: email ).first if profile puts! profile, "UserProfile#generate, already exists" return end user = User.where( email: email ).first if !user user = User.new({ email: email, password: password }) end profile = Ish::UserProfile.new({ email: email, role_name: role_name, }) profile.save if profile.persisted? ; else puts! profile.errors., "Cannot save profile" end end |
.list ⇒ Object
manager uses it. @TODO: check this, this is shit. vp 20170527
90 91 92 93 |
# File 'lib/ish/user_profile.rb', line 90 def self.list out = self.all.order_by( :domain => :asc, :lang => :asc ) [['', nil]] + out.map { |item| [ item.name, item.id ] } end |
Instance Method Details
#bookmarks ⇒ Object
68 69 70 |
# File 'lib/ish/user_profile.rb', line 68 def bookmarks bookmarked_locations end |
#export_fields ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ish/user_profile.rb', line 20 def export_fields %w| email role_name | end |
#has_premium_purchase(item) ⇒ Object
100 101 102 |
# File 'lib/ish/user_profile.rb', line 100 def has_premium_purchase item item.premium_purchases.where( user_profile_id: self.id ).exists? end |
#n_coins ⇒ Object
@deprecated, do not use
76 77 78 |
# File 'lib/ish/user_profile.rb', line 76 def n_coins # @deprecated, do not use n_unlocks end |
#n_stars ⇒ Object
GameUI
98 |
# File 'lib/ish/user_profile.rb', line 98 field :n_stars, type: Integer, default: 0 |
#premium_purchases ⇒ Object
103 104 105 |
# File 'lib/ish/user_profile.rb', line 103 def premium_purchases ::Gameui::PremiumPurchase.where( user_profile_id: self.id ) end |
#sudoer? ⇒ Boolean
84 85 86 |
# File 'lib/ish/user_profile.rb', line 84 def sudoer? %w( [email protected] [email protected] ).include?( self.email ) end |
#videos ⇒ Object
@TODO: do something about this. has_many :stock_watches, class_name: ‘IronWarbler::StockWatch’ has_many :option_watches, class_name: ‘IronWarbler::OptionWatch’
64 |
# File 'lib/ish/user_profile.rb', line 64 has_many :videos, inverse_of: :user_profile |
#videos_embed ⇒ Object
preferences @TODO: better naming convention, or remove this
82 |
# File 'lib/ish/user_profile.rb', line 82 field :videos_embed, :type => Boolean, :default => false |