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
9
10
# 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

Instance Method Details

#as_markedObject


12
13
14
# File 'lib/active_scaffold/marked_model.rb', line 12

def as_marked
  marked_records.include?(id.to_s)
end

#as_marked=(value) ⇒ Object


16
17
18
19
20
21
22
23
# 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_recordsObject

Instance-level access to the marked_records


40
41
42
# File 'lib/active_scaffold/marked_model.rb', line 40

def marked_records
  self.class.marked_records
end