Class: Etwin::Link::LinkAction

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/etwin/link/link_action.rb

Overview

Metadata about a link/unlink action

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, user) ⇒ LinkAction

Returns a new instance of LinkAction.



20
21
22
23
24
# File 'lib/etwin/link/link_action.rb', line 20

def initialize(time, user)
  @time = T.let(time, Time)
  @user = T.let(user, User::ShortUser)
  freeze
end

Instance Attribute Details

#timeObject (readonly)

Returns the value of attribute time.



14
15
16
# File 'lib/etwin/link/link_action.rb', line 14

def time
  @time
end

#userObject (readonly)

Returns the value of attribute user.



17
18
19
# File 'lib/etwin/link/link_action.rb', line 17

def user
  @user
end

Class Method Details

.deserialize(raw) ⇒ Object



85
86
87
88
89
# File 'lib/etwin/link/link_action.rb', line 85

def deserialize(raw)
  time = Time.iso8601(raw['time'])
  user = User::ShortUser.deserialize(raw['user'])
  new(time, user)
end

.from_json(json_str) ⇒ Object



80
81
82
# File 'lib/etwin/link/link_action.rb', line 80

def from_json(json_str)
  deserialize JSON.parse(json_str)
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/etwin/link/link_action.rb', line 27

def ==(other)
  case other
  when LinkAction
    @time == other.time && @user == other.user
  else
    false
  end
end

#as_jsonObject



48
49
50
51
52
53
# File 'lib/etwin/link/link_action.rb', line 48

def as_json
  {
    'time' => @time,
    'user' => @user.as_json
  }
end

#hashObject



37
38
39
# File 'lib/etwin/link/link_action.rb', line 37

def hash
  [@time, @user].hash
end

#inspectObject



56
57
58
# File 'lib/etwin/link/link_action.rb', line 56

def inspect
  PP.singleline_pp(self, String.new)
end

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/etwin/link/link_action.rb', line 61

def pretty_print(pp)  # rubocop:disable Metrics/MethodLength
  pp.group(0, "#{self.class.name}(", ')') do
    pp.nest 1 do
      pp.breakable ''
      pp.text 'time='
      pp.pp @time
      pp.text ','
      pp.breakable ''
      pp.text 'user='
      pp.pp @user
    end
    pp.breakable ''
  end
end

#to_json(opts = nil) ⇒ Object



43
44
45
# File 'lib/etwin/link/link_action.rb', line 43

def to_json(opts = nil)
  JSON.generate(as_json, opts)
end