Class: MuchRailsPubSub::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/much-rails-pub-sub/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name, job_class:) ⇒ Subscription

Returns a new instance of Subscription.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/much-rails-pub-sub/subscription.rb', line 8

def initialize(event_name, job_class:)
  @event_name = event_name
  @job_class = job_class

  unless job_class.respond_to?(:perform_later)
    raise(
      ArgumentError,
      "Invalid job class #{job_class.inspect}: it does not respond to "\
      "the :perform_later method.",
    )
  end
end

Instance Attribute Details

#event_nameObject (readonly)

Returns the value of attribute event_name.



6
7
8
# File 'lib/much-rails-pub-sub/subscription.rb', line 6

def event_name
  @event_name
end

#job_classObject (readonly)

Returns the value of attribute job_class.



6
7
8
# File 'lib/much-rails-pub-sub/subscription.rb', line 6

def job_class
  @job_class
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/much-rails-pub-sub/subscription.rb', line 33

def ==(other)
  if other.is_a?(self.class)
    event_name == other.event_name && job_class == other.job_class
  else
    super
  end
end

#call(params) ⇒ Object



21
22
23
# File 'lib/much-rails-pub-sub/subscription.rb', line 21

def call(params)
  job_class.perform_later(params)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/much-rails-pub-sub/subscription.rb', line 29

def eql?(other)
  job_class.eql?(other.job_class)
end

#hashObject



25
26
27
# File 'lib/much-rails-pub-sub/subscription.rb', line 25

def hash
  job_class.hash
end