Module: Movescount::Concern::Move
- Defined in:
- lib/movescount/concern/move.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#movescount_move ⇒ Object
Get the movescount move.
-
#movescount_save ⇒ Object
Save the points to the database.
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/movescount/concern/move.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#movescount_move ⇒ Object
Get the movescount move
9 10 11 12 |
# File 'lib/movescount/concern/move.rb', line 9 def movescount_move return unless self[[:move_id_column]] && movescount_member @movescount_move ||= Movescount::Move.new(movescount_member, 'MoveID' => self[[:move_id_column]]) end |
#movescount_save ⇒ Object
Save the points to the database
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/movescount/concern/move.rb', line 15 def movescount_save self.class.transaction do # First delete all point public_send([:points_relation]).public_send([:points_clear_method]) # Then for each point create a new point movescount_move.points.each do |point| attributes = {} [:point_attributes].each do |attribute, target| attributes[target] = point.public_send(attribute) if target end unless attributes.empty? if persisted? public_send([:points_relation]).create attributes else public_send([:points_relation]).build attributes end end end end end |