Sha256: 471c1ace637cbe0152419d57ea19a66569fb710e7d52629e97399c4d0402c1e6

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

class Wco::OfficeAction
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'wco_office_actions'

  field     :slug, type: :string
  validates :slug, uniqueness: true, allow_nil: true

  # field :descr, type: :string ## optional

  belongs_to :office_action_template, inverse_of: :office_action
  def tmpl
    office_action_template
  end

  STATUS_ACTIVE   = 'active'
  STATUS_INACTIVE = 'inactive'
  STATUSS         = [ STATUS_ACTIVE, STATUS_INACTIVE ]
  field :status, type: :string
  scope :active, ->{ where( status: STATUS_ACTIVE ) }

  field :perform_at, type: :time

  def do_run
    sch = self
    sch.update!({ status: STATUS_INACTIVE })

    eval( sch.tmpl.action_exe )

    # schedule next actions & update the action
    sch.tmpl.ties.each do |tie|
      next_sch = self.class.find_or_initialize_by({
        office_action_template_id: tie.next_tmpl.id,
      })
      next_sch.perform_at = eval(tie.next_at_exe)
      next_sch.status     = STATUS_ACTIVE
      next_sch.save!
    end
  end

  def to_s
    slug
  end
end
OA ||= Wco::OfficeAction

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wco_models-3.1.0.88 app/models/wco/office_action.rb
wco_models-3.1.0.87 app/models/wco/office_action.rb
wco_models-3.1.0.86 app/models/wco/office_action.rb