Sha256: a7d26468c7a6709fc1e7ae693eedb28e45c47216b07a89e95491ef9ca94c7cf2

Contents?: true

Size: 1.05 KB

Versions: 35

Compression:

Stored size: 1.05 KB

Contents

module ActiveScaffold
  module MarkedModel
    # This is a module aimed at making the make session_stored marked_records available to ActiveRecord models

    def self.included(base)
      base.class_eval do
        extend ClassMethods
        scope :as_marked, -> { where(primary_key => marked_record_ids) }
      end
    end

    def as_marked
      marked_records.include?(id.to_s)
    end

    def as_marked=(value)
      value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value)
      if value == true
        marked_records[id.to_s] = true unless as_marked
      else
        marked_records.delete(id.to_s)
      end
    end

    module ClassMethods
      def marked_records
        Thread.current[:marked_records] ||= {}
      end

      def marked_records=(marked)
        Thread.current[:marked_records] = marked
      end

      def marked_record_ids
        marked_records.keys
      end
    end

    # Instance-level access to the marked_records
    def marked_records
      self.class.marked_records
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
active_scaffold-3.5.5 lib/active_scaffold/marked_model.rb
active_scaffold-3.5.4 lib/active_scaffold/marked_model.rb
active_scaffold-3.5.3 lib/active_scaffold/marked_model.rb
active_scaffold-3.5.2 lib/active_scaffold/marked_model.rb
active_scaffold-3.5.1 lib/active_scaffold/marked_model.rb
active_scaffold-3.5.0 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.43 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.42 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.41.1 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.41 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.40 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.39 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.38 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.37 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.36 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.35 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.34 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.33 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.32 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.31 lib/active_scaffold/marked_model.rb