Class: Woody::Decorators::User

Inherits:
Base
  • Object
show all
Defined in:
lib/woody/decorators/user.rb

Direct Known Subclasses

BrandUser, CreatorUser

Instance Method Summary collapse

Methods inherited from Base

#method_missing

Constructor Details

#initialize(model, config) ⇒ User

Returns a new instance of User.



7
8
9
10
# File 'lib/woody/decorators/user.rb', line 7

def initialize(model, config)
  @config = OpenStruct.new(config)
  super(model)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Woody::Decorators::Base

Instance Method Details

#avatar(platform) ⇒ Object



12
13
14
15
16
17
# File 'lib/woody/decorators/user.rb', line 12

def avatar(platform)
  invalid_platform(platform) unless %w(creator brands).include?(platform)
  return user_avatar(platform: platform) if platform == 'brands'
  return default_avatar(platform) if @model.first_name == ''
  user_avatar(platform: platform, cache_bust: true)
end

#exist?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/woody/decorators/user.rb', line 19

def exist?
  !@model.nil?
end

#first_nameObject



23
24
25
# File 'lib/woody/decorators/user.rb', line 23

def first_name
  @model.first_name
end

#full_name(truncate: false, size: 14) ⇒ Object



27
28
29
30
31
32
# File 'lib/woody/decorators/user.rb', line 27

def full_name(truncate: false, size: 14)
  output = [first_name, last_name].join(' ')

  return output unless output.length >= size && truncate
  truncate(output, size)
end

#idObject



41
42
43
# File 'lib/woody/decorators/user.rb', line 41

def id
  @model.auth0_id
end

#last_nameObject



45
46
47
# File 'lib/woody/decorators/user.rb', line 45

def last_name
  @model.last_name
end

#short_nameObject



34
35
36
37
38
39
# File 'lib/woody/decorators/user.rb', line 34

def short_name
  [
    first_name,
    last_name[0]
  ].join(' ')
end