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



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

.listObject

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

#bookmarksObject



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

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



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_coinsObject

@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_starsObject

GameUI



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

field :n_stars, type: Integer, default: 0

#premium_purchasesObject



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

Returns:

  • (Boolean)


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

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’



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

has_many :videos,    inverse_of: :user_profile

#videos_embedObject

preferences @TODO: better naming convention, or remove this



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

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