Class: SidekiqSimpleDelay::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_simple_delay/utils.rb

Overview

utility methods

Constant Summary collapse

SYSTEM_SIMPLE_CLASSES =
Set.new(
  [
    NilClass,
    TrueClass,
    FalseClass,
    String,
    Symbol
  ]
).freeze
SYSTEM_SIMPLE_COMPLEX_CLASSES =
Set.new(
  [
    Hash,
    Array
  ]
).freeze
SYSTEM_SIMPLE_NUMERIC_CLASSES =
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
  Set.new([Integer, Float]).freeze
else
  Set.new([Fixnum, Bignum, Float]).freeze
end

Class Method Summary collapse

Class Method Details

.simple_object?(obj) ⇒ Boolean

Returns:

  • (Boolean)

33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sidekiq_simple_delay/utils.rb', line 33

def simple_object?(obj)
  klass = obj.class

  if SYSTEM_SIMPLE_COMPLEX_CLASSES.include?(klass)
    obj.all? { |o| simple_object?(o) }
  elsif SYSTEM_SIMPLE_CLASSES.include?(klass)
    true
  elsif SYSTEM_SIMPLE_NUMERIC_CLASSES.include?(klass)
    true
  else
    false
  end
end