Class: BackgroundJobs::Sidekiq::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/background_jobs/strategies/sidekiq/job_attributes_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Attribute

Returns a new instance of Attribute.



47
48
49
# File 'lib/background_jobs/strategies/sidekiq/job_attributes_adapter.rb', line 47

def initialize(value)
  @value = value
end

Instance Method Details

#decodeObject



51
52
53
# File 'lib/background_jobs/strategies/sidekiq/job_attributes_adapter.rb', line 51

def decode
  @value
end

#encodeObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/background_jobs/strategies/sidekiq/job_attributes_adapter.rb', line 55

def encode
  case @value.class.name
    when 'Date'
      "date:#{@value.to_s}"

    when 'Hash'
      HashAttribute.new(@value).encode

    when 'Array'
      ArrayAttribute.new(@value).encode

    when 'Range'
      "range:[#{Attribute.new(@value.first).encode},#{Attribute.new(@value.last).encode}]"

    else
      @value
  end
end