Sha256: ab21ffa41b6b35446d2b82a00873e7b3392e7a75cbea8359d389bda21504956e

Contents?: true

Size: 992 Bytes

Versions: 18

Compression:

Stored size: 992 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 :as_marked, lambda { where(:id => base.marked_records.to_a) }
    end
    
    def as_marked
      marked_records.include?(self.id)
    end
    
    def as_marked=(value)
      value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value)
      if value == true
        marked_records << self.id if !as_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

18 entries across 18 versions & 1 rubygems

Version Path
active_scaffold-3.4.1 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.0.1 lib/active_scaffold/marked_model.rb
active_scaffold-3.4.0 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.3 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.2 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.1 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.0 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.20 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.0.rc3 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.0.rc2 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.19 lib/active_scaffold/marked_model.rb
active_scaffold-3.3.0.rc lib/active_scaffold/marked_model.rb
active_scaffold-3.2.17 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.16 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.15 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.14 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.13 lib/active_scaffold/marked_model.rb
active_scaffold-3.2.12 lib/active_scaffold/marked_model.rb