Class: MuchRailsPubSub::Config

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

Defined Under Namespace

Classes: DefaultPublishedEvents, PublishedEvents, Subscriptions

Constant Summary collapse

TestingPublishedEvents =
Class.new(PublishedEvents)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



62
63
64
65
# File 'lib/much-rails-pub-sub.rb', line 62

def initialize
  @published_events = DefaultPublishedEvents.new
  @publisher_class = MuchRailsPubSub::ActiveJobPublisher
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



60
61
62
# File 'lib/much-rails-pub-sub.rb', line 60

def logger
  @logger
end

#publish_jobObject

Returns the value of attribute publish_job.



60
61
62
# File 'lib/much-rails-pub-sub.rb', line 60

def publish_job
  @publish_job
end

#publish_job_classObject (readonly)

Returns the value of attribute publish_job_class.



59
60
61
# File 'lib/much-rails-pub-sub.rb', line 59

def publish_job_class
  @publish_job_class
end

#published_eventsObject

Returns the value of attribute published_events.



60
61
62
# File 'lib/much-rails-pub-sub.rb', line 60

def published_events
  @published_events
end

#publisher_classObject

Returns the value of attribute publisher_class.



60
61
62
# File 'lib/much-rails-pub-sub.rb', line 60

def publisher_class
  @publisher_class
end

Instance Method Details

#constantize_job(value, type:) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/much-rails-pub-sub.rb', line 80

def constantize_job(value, type:)
  begin
    value.to_s.constantize
  rescue NameError
    raise TypeError, "Unknown #{type} job class: #{value.inspect}."
  end
end

#constantize_publish_job_classObject



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/much-rails-pub-sub.rb', line 67

def constantize_publish_job_class
  @publish_job_class =
    constantize_job(publish_job, type: :publish).tap do |job_class|
      unless publish_job_class?(job_class)
        raise(
          TypeError,
          "Publish job classes must mixin MuchRailsPubSub::PublishJob. "\
          "The given job class, #{job_class.inspect}, does not.",
        )
      end
    end
end

#publish_job_class?(job_class) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/much-rails-pub-sub.rb', line 92

def publish_job_class?(job_class)
  !!(job_class < MuchRailsPubSub::PublishJobBehaviors)
end

#subscriptionsObject



88
89
90
# File 'lib/much-rails-pub-sub.rb', line 88

def subscriptions
  @subscriptions ||= Subscriptions.new
end