Class: SuperSource::User
- Inherits:
-
Object
- Object
- SuperSource::User
- Defined in:
- lib/super_source/user.rb
Constant Summary collapse
- @@current_user =
nil
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(email, name, id, auth_token = nil) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(email, name, id, auth_token = nil) ⇒ User
9 10 11 12 13 14 |
# File 'lib/super_source/user.rb', line 9 def initialize(email, name, id, auth_token = nil) @email = email @name = name @id = id @auth_token = auth_token end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
5 6 7 |
# File 'lib/super_source/user.rb', line 5 def auth_token @auth_token end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/super_source/user.rb', line 5 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/super_source/user.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/super_source/user.rb', line 5 def name @name end |
Class Method Details
.current_user ⇒ Object
40 41 42 |
# File 'lib/super_source/user.rb', line 40 def self.current_user @@current_user ||= User.current_user_from_file end |
.current_user_filename ⇒ Object
16 17 18 |
# File 'lib/super_source/user.rb', line 16 def self.current_user_filename "#{ SuperSource.user_supso_config_root }/current_user.json" end |
.current_user_from_file ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/super_source/user.rb', line 20 def self.current_user_from_file if !File.exist?(User.current_user_filename) return nil end user_data = {} begin user_data = JSON.parse(File.read(User.current_user_filename)) user_data = {} if !user_data.is_a?(Object) rescue JSON::ParserError => err user_data = {} end if user_data['email'] || user_data['auth_token'] User.new(user_data['email'], user_data['name'], user_data['id'], user_data['auth_token']) else nil end end |