module ActiveScaffold::MarkedModel

Public Class Methods

included(base) click to toggle source

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

# File lib/active_scaffold/marked_model.rb, line 5
def self.included(base)
  base.class_eval do
    extend ClassMethods
    scope :as_marked, -> { where(primary_key => marked_record_ids) }
  end
end

Public Instance Methods

as_marked() click to toggle source
# File lib/active_scaffold/marked_model.rb, line 12
def as_marked
  marked_records.include?(id.to_s)
end
as_marked=(value) click to toggle source
# File lib/active_scaffold/marked_model.rb, line 16
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
marked_records() click to toggle source

Instance-level access to the marked_records

# File lib/active_scaffold/marked_model.rb, line 40
def marked_records
  self.class.marked_records
end