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

Instance Method Summary collapse

Class Method Details

.action_subscribe?(action) ⇒ Boolean

method used to determine if a action is a subsribe action

Parameters:

  • action (string)

    The action that will be checked

Returns:

  • (Boolean)

    Returns true if the action equals to ‘subscribe’



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

Parameters:

  • error (Exception::Error)

Returns:

  • (Boolean)

    returns true if the error should be filtered otherwise false



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

Parameters:

  • message (Object)


125
126
127
# File 'lib/celluloid_pubsub/helper.rb', line 125

def log_debug(message)
  debug message 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

Parameters:

  • options (Hash, Array)

    the options that need to be parsed

Returns:

  • (Hash)


112
113
114
115
116
# File 'lib/celluloid_pubsub/helper.rb', line 112

def parse_options(options)
  options = options.is_a?(Array) ? options.first : options
  options = options.is_a?(Hash) ? options.stringify_keys : {}
  options
end

.setup_celluloid_exception_handlervoid

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_loggervoid

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_filevoid

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, options = {})
  options.stringify_keys!
  version = get_parsed_version(version)
  get_parsed_version(gem_version).send(options.fetch('operator', '<='), version)
end

Instance Method Details

#succesfull_subscription?(message) ⇒ Boolean

checks if the message has the successfull subscription action

Parameters:

  • message (string)

    The message that will be checked

Returns:

  • (Boolean)

    return true if message contains key client_action with value ‘succesfull_subscription’



11
12
13
# File 'lib/celluloid_pubsub/helper.rb', line 11

def succesfull_subscription?(message)
  message.is_a?(Hash) && message['client_action'] == 'successful_subscription'
end