Class: Leash::User

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/types.rb

Overview

Authenticated Leash user.

Mirrors the TS ‘LeashUser` interface — JSON fields use camelCase on the wire (`id`, `email`, `name`, `picture`), and on the Ruby side `picture` is optional. Two `LeashUser`s are equal when every attribute matches.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, email:, name: nil, picture: nil) ⇒ User

Returns a new instance of User.



12
13
14
15
16
17
# File 'lib/leash/types.rb', line 12

def initialize(id:, email:, name: nil, picture: nil)
  @id = id
  @email = email
  @name = name
  @picture = picture
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



10
11
12
# File 'lib/leash/types.rb', line 10

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/leash/types.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/leash/types.rb', line 10

def name
  @name
end

#pictureObject (readonly)

Returns the value of attribute picture.



10
11
12
# File 'lib/leash/types.rb', line 10

def picture
  @picture
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



19
20
21
22
23
24
25
# File 'lib/leash/types.rb', line 19

def ==(other)
  other.is_a?(User) &&
    id == other.id &&
    email == other.email &&
    name == other.name &&
    picture == other.picture
end

#hashObject



29
30
31
# File 'lib/leash/types.rb', line 29

def hash
  [self.class, id, email, name, picture].hash
end

#to_hObject



33
34
35
36
37
# File 'lib/leash/types.rb', line 33

def to_h
  h = { id: id, email: email, name: name }
  h[:picture] = picture if picture
  h
end