Sha256: 46259073381e6eca9c45d14d345f3446cb874f46eac0a0ffe81b9c1c3b2764c7

Contents?: true

Size: 802 Bytes

Versions: 5

Compression:

Stored size: 802 Bytes

Contents

module Unidom::Position::Concerns::AsSuperiorPost

  extend ActiveSupport::Concern

  included do |includer|

    has_many :inferior_post_reporting_structures, class_name: 'Unidom::Position::PostReportingStructure', source: :superior_post, foreign_key: :superior_post_id
    has_many :inferior_posts,                     through:    :inferior_post_reporting_structures,        source: :inferior_post

    def is_reported_to!(by: nil, at: Time.now, primary: true)
      inferior_post_reporting_structures.inferior_post_is(by).valid_at(now: at).alive.first_or_create! elemental: primary, opened_at: at
    end

    def is_reported_to?(by: nil, at: Time.now, primary: true)
      inferior_post_reporting_structures.inferior_post_is(by).valid_at(now: at).alive.primary(primary).exists?
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
unidom-position-1.4.4 app/models/unidom/position/concerns/as_superior_post.rb
unidom-position-1.4.3 app/models/unidom/position/concerns/as_superior_post.rb
unidom-position-1.4.2 app/models/unidom/position/concerns/as_superior_post.rb
unidom-position-1.4.1 app/models/unidom/position/concerns/as_superior_post.rb
unidom-position-1.4 app/models/unidom/position/concerns/as_superior_post.rb