Sha256: 99e655c3fbfabdb735d1cdc1302d058795956ccb91515ef4278762d1c2c79f72

Contents?: true

Size: 990 Bytes

Versions: 90

Compression:

Stored size: 990 Bytes

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.extend ClassMethods
      base.scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}}
    end
    
    def marked
      marked_records.include?(self.id)
    end
    
    def marked=(value)
      value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value)
      if value == true
        marked_records << self.id if !marked
      else
        marked_records.delete(self.id)
      end
    end
  
    module ClassMethods
      def marked_records
        Thread.current[:marked_records] ||= Set.new
      end

      def marked_records=(marked)
        Thread.current[:marked_records] = marked 
      end
    end
  
    # Instance-level access to the marked_records
    def marked_records
      self.class.marked_records
    end
  end
end

Version data entries

90 entries across 90 versions & 5 rubygems

Version Path
active_scaffold_vho-3.2.14 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.13 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.12 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.11 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.10 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.9 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.8 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.7 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.6 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.5 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.4 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.3 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.2 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.1 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.2.0 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.0.31 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.1.8 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.0.30 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.0.29 lib/active_scaffold/marked_model.rb
active_scaffold_vho-3.1.6 lib/active_scaffold/marked_model.rb