module Movescount::Concern::Move
Public Class Methods
included(base)
click to toggle source
# File lib/movescount/concern/move.rb, line 4 def self.included(base) base.extend ClassMethods end
Public Instance Methods
movescount_move()
click to toggle source
Get the movescount move
# File lib/movescount/concern/move.rb, line 9 def movescount_move return unless self[movescount_options[:move_id_column]] && movescount_member @movescount_move ||= Movescount::Move.new(movescount_member, 'MoveID' => self[movescount_options[:move_id_column]]) end
movescount_save()
click to toggle source
Save the points to the database
# File lib/movescount/concern/move.rb, line 15 def movescount_save self.class.transaction do # First delete all point public_send(movescount_options[:points_relation]).public_send(movescount_options[:points_clear_method]) # Then for each point create a new point movescount_move.points.each do |point| attributes = {} movescount_options[:point_attributes].each do |attribute, target| attributes[target] = point.public_send(attribute) if target end unless attributes.empty? if persisted? public_send(movescount_options[:points_relation]).create attributes else public_send(movescount_options[:points_relation]).build attributes end end end end end
Private Instance Methods
movescount_member()
click to toggle source
Returns the movescount member object
# File lib/movescount/concern/move.rb, line 44 def movescount_member return unless public_send(movescount_options[:member_relation]) public_send(movescount_options[:member_relation]).movescount_member end
movescount_options()
click to toggle source
Get the set options. Getting the defaults is ugly with send but its ok for now
# File lib/movescount/concern/move.rb, line 39 def movescount_options self.class.movescount_options || self.class.send(:movescount) end