Sha256: 7d4224b3ee6afbb21570af563b69d657685b950e51bd61cf8382511b007ec92f

Contents?: true

Size: 794 Bytes

Versions: 23

Compression:

Stored size: 794 Bytes

Contents

module Locomotive
  module Concerns
    module ContentEntry
      module Counter

        extend ActiveSupport::Concern

        included do

          ## callbacks ##
          after_create  :inc_number_of_entries
          after_destroy :dec_number_of_entries

        end

        private

        def inc_number_of_entries
          change_number_of_entries(1)
        end

        def dec_number_of_entries
          change_number_of_entries(-1)
        end

        def change_number_of_entries(delta)
          Locomotive::ContentType.collection.update_one(
            { _id: self.content_type_id },
            {
              '$inc' => { 'number_of_entries' => delta },
              '$set' => { 'updated_at' => Time.zone.now }
            })
        end

      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.2.0.alpha1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.1.1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.1.0 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.1.0.rc1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.3 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.2 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.0 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.0.rc0 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.0.alpha3 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.4.1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.0.alpha2 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-4.0.0.alpha1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.4.0 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.3.0 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.3.0.rc3 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.3.0.rc2 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.2.1 app/models/locomotive/concerns/content_entry/counter.rb
locomotivecms-3.3.0.rc1 app/models/locomotive/concerns/content_entry/counter.rb