Module: CelluloidPubsub::Helper
- Included in:
- BaseActor, ClientConnection
- Defined in:
- lib/celluloid_pubsub/helper.rb
Overview
class that holds the options that are configurable for this gem
Class Method Summary collapse
-
.action_subscribe?(action) ⇒ Boolean
method used to determine if a action is a subsribe action.
-
.fetch_gem_version(gem_name) ⇒ Float?
returns the parsed version of the gem.
-
.filtered_error?(error) ⇒ Boolean
private
checks if a given error needs to be filtered.
-
.find_loaded_gem(name, property = nil) ⇒ String?
returns the gem’s property from its speification or nil.
-
.find_loaded_gem_property(gem_name, property = 'version') ⇒ String?
returns the gem’s property from its speification or nil.
-
.get_parsed_version(version) ⇒ Float?
returns the parsed version as a float or nil.
-
.log_debug(message) ⇒ void
private
receives a message, and logs it to the log file if debug is enabled.
-
.parse_options(options) ⇒ Hash
private
receives a list of options that need to be parsed if it is an Array will return the first element , otherwise if it is an Hash will return the hash with string keys, otherwise an empty hash.
-
.setup_celluloid_exception_handler ⇒ void
private
sets the celluloid exception handler.
-
.setup_celluloid_logger ⇒ void
private
sets the celluloid logger and the celluloid exception handler.
-
.setup_log_file ⇒ void
private
creates the log file where the debug messages will be printed.
-
.verify_gem_version(gem_version, version, options = {}) ⇒ Boolean
returns true if gem_version is less or equal to the specified version, otherwise false.
Instance Method Summary collapse
-
#actor_dead?(actor) ⇒ Boolean
the method try to decide if an actor is dead In Celluloid 0.18 there is no ‘dead?` method anymore So we are trying to be backward-compatible with older versions.
-
#cell_actor ⇒ ::Celluloid::Actor
returns the current actor.
-
#own_self ⇒ Object
returns the instance of the class that includes the actor, this is useful in tests.
-
#succesfull_subscription?(message) ⇒ Boolean
checks if the message has the successfull subscription action.
Class Method Details
.action_subscribe?(action) ⇒ Boolean
method used to determine if a action is a subsribe action
118 119 120 |
# File 'lib/celluloid_pubsub/helper.rb', line 118 def action_subscribe?(action) action == 'subscribe' end |
.fetch_gem_version(gem_name) ⇒ Float?
returns the parsed version of the gem
82 83 84 85 |
# File 'lib/celluloid_pubsub/helper.rb', line 82 def fetch_gem_version(gem_name) version = find_loaded_gem_property(gem_name) version.blank? ? nil : get_parsed_version(version) end |
.filtered_error?(error) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
checks if a given error needs to be filtered
177 178 179 |
# File 'lib/celluloid_pubsub/helper.rb', line 177 def filtered_error?(error) [Interrupt].any? { |class_name| error.is_a?(class_name) } end |
.find_loaded_gem(name, property = nil) ⇒ String?
returns the gem’s property from its speification or nil
60 61 62 63 |
# File 'lib/celluloid_pubsub/helper.rb', line 60 def find_loaded_gem(name, property = nil) gem_spec = Gem.loaded_specs.values.find { |repo| repo.name == name } gem_spec.present? && property.present? ? gem_spec.send(property) : gem_spec end |
.find_loaded_gem_property(gem_name, property = 'version') ⇒ String?
returns the gem’s property from its speification or nil
72 73 74 |
# File 'lib/celluloid_pubsub/helper.rb', line 72 def find_loaded_gem_property(gem_name, property = 'version') find_loaded_gem(gem_name, property) end |
.get_parsed_version(version) ⇒ Float?
returns the parsed version as a float or nil
93 94 95 96 |
# File 'lib/celluloid_pubsub/helper.rb', line 93 def get_parsed_version(version) version_parser = CelluloidPubsub::GemVersionParser.new(version) version_parser.parsed_number end |
.log_debug(message) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
receives a message, and logs it to the log file if debug is enabled
:nocov:
203 204 205 206 207 |
# File 'lib/celluloid_pubsub/helper.rb', line 203 def log_debug() return unless respond_to?(:debug_enabled?) return if Celluloid.logger.blank? || !debug_enabled? Celluloid.logger.debug() end |
.parse_options(options) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
receives a list of options that need to be parsed if it is an Array will return the first element , otherwise if it is an Hash will return the hash with string keys, otherwise an empty hash
190 191 192 193 |
# File 'lib/celluloid_pubsub/helper.rb', line 190 def () = .is_a?(Array) ? .last : .is_a?(Hash) ? .deep_stringify_keys : {} end |
.setup_celluloid_exception_handler ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
sets the celluloid exception handler
:nocov:
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/celluloid_pubsub/helper.rb', line 144 def setup_celluloid_exception_handler Celluloid.task_class = defined?(Celluloid::TaskThread) ? Celluloid::TaskThread : Celluloid::Task::Threaded Celluloid.exception_handler do |ex| unless filtered_error?(ex) puts ex puts ex.backtrace puts ex.cause end end end |
.setup_celluloid_logger ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
sets the celluloid logger and the celluloid exception handler
:nocov:
128 129 130 131 132 133 134 135 |
# File 'lib/celluloid_pubsub/helper.rb', line 128 def setup_celluloid_logger return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) setup_log_file Celluloid.logger = ::Logger.new(log_file_path).tap do |logger| logger.level = respond_to?(:log_level) ? log_level : ::Logger::Severity::INFO end setup_celluloid_exception_handler end |
.setup_log_file ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
creates the log file where the debug messages will be printed
:nocov:
162 163 164 165 166 167 |
# File 'lib/celluloid_pubsub/helper.rb', line 162 def setup_log_file return if !debug_enabled? || (respond_to?(:log_file_path) && log_file_path.blank?) FileUtils.mkdir_p(File.dirname(log_file_path)) unless File.directory?(log_file_path) log_file = File.open(log_file_path, 'wb') log_file.sync = true end |
.verify_gem_version(gem_version, version, options = {}) ⇒ Boolean
returns true if gem_version is less or equal to the specified version, otherwise false
106 107 108 109 110 |
# File 'lib/celluloid_pubsub/helper.rb', line 106 def verify_gem_version(gem_version, version, = {}) .stringify_keys! version = get_parsed_version(version) get_parsed_version(gem_version).send(.fetch('operator', '<='), version) end |
Instance Method Details
#actor_dead?(actor) ⇒ Boolean
the method try to decide if an actor is dead In Celluloid 0.18 there is no ‘dead?` method anymore
So we are trying to be backward-compatible with older versions
27 28 29 30 31 |
# File 'lib/celluloid_pubsub/helper.rb', line 27 def actor_dead?(actor) raise actor.class.inspect if !actor.respond_to?(:dead?) && !actor.respond_to?(:alive?) (actor.respond_to?(:dead?) && actor.dead?) || (actor.respond_to?(:alive?) && !actor.alive?) end |
#cell_actor ⇒ ::Celluloid::Actor
returns the current actor
47 48 49 |
# File 'lib/celluloid_pubsub/helper.rb', line 47 def cell_actor ::Celluloid::Actor.current end |
#own_self ⇒ Object
returns the instance of the class that includes the actor, this is useful in tests
38 39 40 |
# File 'lib/celluloid_pubsub/helper.rb', line 38 def own_self self end |
#succesfull_subscription?(message) ⇒ Boolean
checks if the message has the successfull subscription action
15 16 17 |
# File 'lib/celluloid_pubsub/helper.rb', line 15 def succesfull_subscription?() .is_a?(Hash) && ['client_action'] == 'successful_subscription' end |