Sha256: 7d878b0ceb95beef0c2857b92d671c99969de88dfad53d0c8097ef0c1be4793b

Contents?: true

Size: 891 Bytes

Versions: 62

Compression:

Stored size: 891 Bytes

Contents

module Workarea
  module Commentable
    extend ActiveSupport::Concern

    included do
      field :subscribed_user_ids, type: Array, default: []
      has_many :comments,
        class_name: 'Workarea::Comment',
        as: :commentable

      before_save do
        subscribed_user_ids.map!(&:to_s).map!(&:downcase) if subscribed_user_ids.present?
      end
    end

    def add_subscription(list)
      all = subscribed_user_ids + clean_subscription_list(list)
      update_attribute(:subscribed_user_ids, all.uniq)
    end

    def remove_subscription(list)
      update_attribute(
        :subscribed_user_ids,
        subscribed_user_ids - clean_subscription_list(list)
      )
    end

    private

    def clean_subscription_list(list)
      list = list.join(',') if list.respond_to?(:join)
      list.to_s.split(',').map(&:strip).map(&:downcase).reject(&:blank?)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/commentable.rb
workarea-core-3.5.26 app/models/workarea/commentable.rb
workarea-core-3.4.45 app/models/workarea/commentable.rb
workarea-core-3.5.25 app/models/workarea/commentable.rb
workarea-core-3.5.23 app/models/workarea/commentable.rb
workarea-core-3.4.44 app/models/workarea/commentable.rb
workarea-core-3.5.22 app/models/workarea/commentable.rb
workarea-core-3.4.43 app/models/workarea/commentable.rb
workarea-core-3.5.21 app/models/workarea/commentable.rb
workarea-core-3.4.42 app/models/workarea/commentable.rb
workarea-core-3.5.20 app/models/workarea/commentable.rb
workarea-core-3.4.41 app/models/workarea/commentable.rb
workarea-core-3.5.19 app/models/workarea/commentable.rb
workarea-core-3.4.40 app/models/workarea/commentable.rb
workarea-core-3.5.18 app/models/workarea/commentable.rb
workarea-core-3.4.39 app/models/workarea/commentable.rb
workarea-core-3.5.17 app/models/workarea/commentable.rb
workarea-core-3.4.38 app/models/workarea/commentable.rb
workarea-core-3.5.16 app/models/workarea/commentable.rb
workarea-core-3.4.37 app/models/workarea/commentable.rb