Module: CelluloidPubsub::Helper
- Included in:
- BaseActor
- 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) ⇒ Object
-
.filtered_error?(error) ⇒ Boolean
private
checks if a given error needs to be filtered.
- .find_loaded_gem(name, property = nil) ⇒ Object
- .find_loaded_gem_property(gem_name, property = 'version') ⇒ Object
- .get_parsed_version(version) ⇒ Object
-
.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 = {}) ⇒ Object
Instance Method Summary collapse
-
#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
52 53 54 |
# File 'lib/celluloid_pubsub/helper.rb', line 52 def action_subscribe?(action) action == 'subscribe' end |
.fetch_gem_version(gem_name) ⇒ Object
26 27 28 29 |
# File 'lib/celluloid_pubsub/helper.rb', line 26 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
99 100 101 |
# File 'lib/celluloid_pubsub/helper.rb', line 99 def filtered_error?(error) [Interrupt].any? { |class_name| error.is_a?(class_name) } end |
.find_loaded_gem(name, property = nil) ⇒ Object
17 18 19 20 |
# File 'lib/celluloid_pubsub/helper.rb', line 17 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') ⇒ Object
22 23 24 |
# File 'lib/celluloid_pubsub/helper.rb', line 22 def find_loaded_gem_property(gem_name, property = 'version') find_loaded_gem(gem_name, property) end |
.get_parsed_version(version) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/celluloid_pubsub/helper.rb', line 31 def get_parsed_version(version) return 0 if version.blank? version = version.to_s.split('.') if version.size > 2 version.pop until version.size == 2 end version.join('.').to_f 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
125 126 127 |
# File 'lib/celluloid_pubsub/helper.rb', line 125 def log_debug() debug if respond_to?(:debug_enabled?) && debug_enabled? 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
112 113 114 115 116 |
# File 'lib/celluloid_pubsub/helper.rb', line 112 def () = .is_a?(Array) ? .first : = .is_a?(Hash) ? .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
73 74 75 76 77 78 |
# File 'lib/celluloid_pubsub/helper.rb', line 73 def setup_celluloid_exception_handler Celluloid.task_class = defined?(Celluloid::TaskThread) ? Celluloid::TaskThread : Celluloid::Task::Threaded Celluloid.exception_handler do |ex| puts ex unless filtered_error?(ex) 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
61 62 63 64 65 66 |
# File 'lib/celluloid_pubsub/helper.rb', line 61 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.present? ? log_file_path : STDOUT) 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
85 86 87 88 89 90 |
# File 'lib/celluloid_pubsub/helper.rb', line 85 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, 'w') log_file.sync = true end |
.verify_gem_version(gem_version, version, options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/celluloid_pubsub/helper.rb', line 40 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
#succesfull_subscription?(message) ⇒ Boolean
checks if the message has the successfull subscription action
11 12 13 |
# File 'lib/celluloid_pubsub/helper.rb', line 11 def succesfull_subscription?() .is_a?(Hash) && ['client_action'] == 'successful_subscription' end |