Class: ActsAsCaesar::ActiveRecordPersistence
- Inherits:
-
Object
- Object
- ActsAsCaesar::ActiveRecordPersistence
- Defined in:
- lib/acts_as_caesar/services/active_record_persistence.rb
Class Method Summary collapse
Instance Method Summary collapse
- #candidate ⇒ Object
-
#initialize(klass, id) ⇒ ActiveRecordPersistence
constructor
A new instance of ActiveRecordPersistence.
- #update_score ⇒ Object
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
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
#candidate ⇒ Object
19 20 21 |
# File 'lib/acts_as_caesar/services/active_record_persistence.rb', line 19 def candidate @candidate ||= @klass.find(@id) end |
#update_score ⇒ Object
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 |