Module: GoodJob::Job::LockTypeAccessor

Included in:
GoodJob::Job
Defined in:
app/models/good_job/job.rb

Constant Summary collapse

LOCK_TYPES =
{ "advisory" => 0, "skiplocked" => 1, "hybrid" => 2 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



40
41
42
# File 'app/models/good_job/job.rb', line 40

def self.included(klass)
  klass.define_singleton_method(:lock_types) { LockTypeAccessor::LOCK_TYPES }
end

Instance Method Details

#lock_typeObject



44
45
46
47
48
# File 'app/models/good_job/job.rb', line 44

def lock_type
  return nil unless has_attribute?(:lock_type)

  LockTypeAccessor::LOCK_TYPES.key(read_attribute(:lock_type))
end

#lock_type=(value) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/models/good_job/job.rb', line 50

def lock_type=(value)
  return unless has_attribute?(:lock_type)

  write_attribute(:lock_type, case value
                              when Symbol then LockTypeAccessor::LOCK_TYPES[value.to_s]
                              when String then LockTypeAccessor::LOCK_TYPES[value]
                              else value
                              end)
end