Class: Ish::UserProfile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Utils

#export

Methods included from Mongoid::Voter

#unvote, #vote, #vote_value, #voted?, #votees

Class Method Details

.generate(delta) ⇒ Object

used in rake tasks



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
136
# File 'lib/ish/user_profile.rb', line 110

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.full_messages, "Cannot save profile"
  end
end

.listObject

manager uses it. @TODO: check this, this is shit. vp 20170527



91
92
93
94
# File 'lib/ish/user_profile.rb', line 91

def self.list
  out = self.all.order_by( :domain => :asc, :lang => :asc )
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
end

Instance Method Details

#bookmarksObject



69
70
71
# File 'lib/ish/user_profile.rb', line 69

def bookmarks
  bookmarked_locations
end

#export_fieldsObject



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



101
102
103
# File 'lib/ish/user_profile.rb', line 101

def has_premium_purchase item
  item.premium_purchases.where( user_profile_id: self.id ).exists?
end

#n_coinsObject

@deprecated, do not use



77
78
79
# File 'lib/ish/user_profile.rb', line 77

def n_coins # @deprecated, do not use
  n_unlocks
end

#n_starsObject

GameUI



99
# File 'lib/ish/user_profile.rb', line 99

field :n_stars, type: Integer, default: 0

#premium_purchasesObject



104
105
106
# File 'lib/ish/user_profile.rb', line 104

def premium_purchases
  ::Gameui::PremiumPurchase.where( user_profile_id: self.id )
end

#sudoer?Boolean



85
86
87
# File 'lib/ish/user_profile.rb', line 85

def sudoer?
  %w( [email protected] [email protected] ).include?( self.email )
end

#videosObject

@TODO: do something about this. has_many :stock_watches, class_name: ‘IronWarbler::StockWatch’ has_many :option_watches, class_name: ‘IronWarbler::OptionWatch’



65
# File 'lib/ish/user_profile.rb', line 65

has_many :videos,    inverse_of: :user_profile

#videos_embedObject

preferences @TODO: better naming convention, or remove this



83
# File 'lib/ish/user_profile.rb', line 83

field :videos_embed, :type => Boolean, :default => false