Class: Etwin::Link::LinkAction
- Inherits:
-
Object
- Object
- Etwin::Link::LinkAction
- 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
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json ⇒ Object
- #hash ⇒ Object
-
#initialize(time, user) ⇒ LinkAction
constructor
A new instance of LinkAction.
- #inspect ⇒ Object
-
#pretty_print(pp) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #to_json(opts = nil) ⇒ Object
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
#time ⇒ Object (readonly)
Returns the value of attribute time.
14 15 16 |
# File 'lib/etwin/link/link_action.rb', line 14 def time @time end |
#user ⇒ Object (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_json ⇒ Object
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 |
#hash ⇒ Object
37 38 39 |
# File 'lib/etwin/link/link_action.rb', line 37 def hash [@time, @user].hash end |
#inspect ⇒ Object
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 |