Module: ActiveScaffold::MarkedModel

Defined in:
lib/active_scaffold/marked_model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

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



5
6
7
8
# File 'lib/active_scaffold/marked_model.rb', line 5

def self.included(base)
  base.extend ClassMethods
  base.scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}}
end

Instance Method Details

#markedObject



10
11
12
# File 'lib/active_scaffold/marked_model.rb', line 10

def marked
  marked_records.include?(self.id)
end

#marked=(value) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/active_scaffold/marked_model.rb', line 14

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

#marked_recordsObject

Instance-level access to the marked_records



34
35
36
# File 'lib/active_scaffold/marked_model.rb', line 34

def marked_records
  self.class.marked_records
end