Class: ActsAsCaesar::ActiveRecordPersistence

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_caesar/services/active_record_persistence.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, id) ⇒ ActiveRecordPersistence

Returns a new instance of ActiveRecordPersistence.



10
11
12
13
# File 'lib/acts_as_caesar/services/active_record_persistence.rb', line 10

def initialize(klass, id)
  @klass = klass
  @id = id
end

Class Method Details

.can_handle?(klass) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/acts_as_caesar/services/active_record_persistence.rb', line 4

def can_handle?(klass)
  defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
  (klass < ActiveRecord::Base)
end

Instance Method Details

#candidateObject



19
20
21
# File 'lib/acts_as_caesar/services/active_record_persistence.rb', line 19

def candidate
  @candidate ||= @klass.find(@id)
end

#update_scoreObject



15
16
17
# File 'lib/acts_as_caesar/services/active_record_persistence.rb', line 15

def update_score
  candidate.update_attribute(:score, candidate.total_candidate_score)
end