Sha256: fbfa5817d741f71e75c86bd248353c2eb93c244b903188066334f8d723126c69

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

##
# As Post Fulfiller 是履行职位的参与者的领域逻辑关注点。

module Unidom::Accession::Concerns::AsPostFulfiller

  extend ActiveSupport::Concern

  included do |includer|

    has_many :post_fulfillments, class_name: 'Unidom::Accession::PostFulfillment', as:     :fulfiller
    has_many :fulfilled_posts,   through:    :post_fulfillments,                   source: :fulfilled, source_type: 'Unidom::Position::Post'

    ##
    # 让当前参与者在指定时间 at 开始履行岗位 post 。指定时间缺省为当前时间。如:
    # selected_person.fulfill_post! post
    # 或者
    # selected_person.fulfill_post! post, at: Time.now-1.day
    def fulfill_post!(post, at: Time.now)
      raise ArgumentError.new('The post argument is required.') if post.blank?
      raise ArgumentError.new('The at argument is required.'  ) if at.blank?
      post_fulfillments.create! fulfilled: post, opened_at: at
    end

    ##
    # 判断当前参与者在指定时间 at 是否被履行制定的岗位 post 。指定时间缺省为当前时间。如:
    # post.fulfill_post? post
    # 或者
    # post.fulfill_post? post, at: Time.now
    def fulfill_post?(post, at: Time.now)
      raise ArgumentError.new('The post argument is required.') if post.blank?
      raise ArgumentError.new('The at argument is required.'  ) if at.blank?
      post_fulfillments.fulfilled_is(post).valid_at(now: at).exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unidom-accession-2.3.3 app/models/unidom/accession/concerns/as_post_fulfiller.rb
unidom-accession-2.3.2 app/models/unidom/accession/concerns/as_post_fulfiller.rb
unidom-accession-2.3.1 app/models/unidom/accession/concerns/as_post_fulfiller.rb