Sha256: cf6adf717e06fc27e08257ed1eec6196b0737e182ca2b7940287929abd0ea7e5

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

module CalculateStat

  def self.included(base)
    base.extend ClassMethods
    base.send :include, InstanceMethods
    base.class_eval do
      validates_presence_of :start_date, :end_date
      validate :check_date
    end
  end

  module ClassMethods
    def calculate_stat
      self.not_calculated.each do |stat|
        stat.transition_to!(:started)
      end
    end
  end

  module InstanceMethods
    def check_date
      if self.start_date and self.end_date
        if self.start_date >= self.end_date
          errors.add(:start_date)
          errors.add(:end_date)
        end
      end
    end

    def send_message
      sender = User.find(1) # system
      message_template = MessageTemplate.localized_template('counting_completed', user.profile.locale)
      request = MessageRequest.new
      request.assign_attributes({:sender => sender, :receiver => user, :message_template => message_template})
      request.save_message_body
      request.transition_to!(:sent)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enju_leaf-1.1.0.rc17 lib/enju_leaf/calculate_stat.rb