Sha256: 1fdc9ab5f450a7d4d636e335b94fa034324bc07fe141943349f3ace870149bb6

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 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)
      if [true, 'true', 1, '1', 'T', 't'].include?(value.respond_to?(:downcase) ? value.downcase : value)
        marked_records[id.to_s] = true unless as_marked
      else
        marked_records.delete(id.to_s)
      end
    end

    module ClassMethods
      def marked_records
        ActiveScaffold::Registry.marked_records ||= {}
      end

      def marked_records=(marked)
        ActiveScaffold::Registry.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

6 entries across 6 versions & 1 rubygems

Version Path
active_scaffold-4.0.2 lib/active_scaffold/marked_model.rb
active_scaffold-4.0.1 lib/active_scaffold/marked_model.rb
active_scaffold-4.0.0 lib/active_scaffold/marked_model.rb
active_scaffold-4.0.0.rc3 lib/active_scaffold/marked_model.rb
active_scaffold-4.0.0.rc2 lib/active_scaffold/marked_model.rb
active_scaffold-4.0.0.rc1 lib/active_scaffold/marked_model.rb