Sha256: d9f58d06a0b62027280de700f8c4a598f5a0fac8452dde3b716c7968eca691b9

Contents?: true

Size: 993 Bytes

Versions: 39

Compression:

Stored size: 993 Bytes

Contents

module CalculateStat
  extend ActiveSupport::Concern

  included do
    validates_presence_of :start_date, :end_date
    validate :check_date

    # 利用統計の集計を開始します。
    def self.calculate_stat
      self.not_calculated.each do |stat|
        stat.transition_to!(:started)
      end
    end
  end

  # 利用統計の日付をチェックします。
  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

Version data entries

39 entries across 37 versions & 2 rubygems

Version Path
enju_library-0.3.0.beta.2 app/models/concerns/calculate_stat.rb
enju_library-0.2.5 app/models/concerns/calculate_stat.rb
enju_library-0.2.4 app/models/concerns/calculate_stat.rb
enju_library-0.2.3 app/models/concerns/calculate_stat.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/enju_library-0.2.2/app/models/concerns/calculate_stat.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/bundler/gems/enju_library-d36f415e177e/app/models/concerns/calculate_stat.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/enju_library-0.2.1/app/models/concerns/calculate_stat.rb
enju_library-0.2.2 app/models/concerns/calculate_stat.rb
enju_library-0.2.1 app/models/concerns/calculate_stat.rb
enju_library-0.2.0 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.10 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.9 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.8 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.7 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.6 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.5 app/models/concerns/calculate_stat.rb
enju_library-0.2.0.beta.4 app/models/concerns/calculate_stat.rb
enju_leaf-1.2.0.beta.2 app/models/concerns/calculate_stat.rb
enju_leaf-1.2.0.beta.1 app/models/concerns/calculate_stat.rb