Class: Caboose::BlockCache

Inherits:
Object
  • Object
show all
Defined in:
app/models/caboose/block_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(b) ⇒ BlockCache

def render(block, options = nil)

block = self.child(block) if block && block.is_a?(String)
eval("CabooseBlockRendering::render_block_type_#{block.block_type_id}(block)")

end


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/caboose/block_cache.rb', line 52

def initialize(b)
  self.id                     = b.id                    
  self.page_id                = b.page_id
  self.parent_id              = b.parent_id 
  self.block_type_id          = b.block_type_id
  self.block_type_field_type  = b.block_type ? b.block_type.field_type : nil
  self.sort_order             = b.sort_order
  self.name                   = b.name
  self.value                  = b.value
  self.file                   = BlockCacheFile.new(b.file)
  self.image                  = BlockCacheImage.new(b.image)
  self.children = b.children.collect{ |b2| BlockCache.new(b2) }
end

Instance Attribute Details

#block_type_field_typeObject

Returns the value of attribute block_type_field_type


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def block_type_field_type
  @block_type_field_type
end

#block_type_idObject

Returns the value of attribute block_type_id


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def block_type_id
  @block_type_id
end

#childrenObject

Returns the value of attribute children


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def children
  @children
end

#fileObject

Returns the value of attribute file


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def file
  @file
end

#idObject

Returns the value of attribute id


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def id
  @id
end

#imageObject

Returns the value of attribute image


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def image
  @image
end

#nameObject

Returns the value of attribute name


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def name
  @name
end

#page_idObject

Returns the value of attribute page_id


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def page_id
  @page_id
end

#parent_idObject

Returns the value of attribute parent_id


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def parent_id
  @parent_id
end

#sort_orderObject

Returns the value of attribute sort_order


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def sort_order
  @sort_order
end

#valueObject

Returns the value of attribute value


4
5
6
# File 'app/models/caboose/block_cache.rb', line 4

def value
  @value
end

Instance Method Details

#child(name) ⇒ Object


24
25
26
27
28
29
# File 'app/models/caboose/block_cache.rb', line 24

def child(name)
  self.children.each do |kid|
    return kid if kid.name == name
  end
  return nil    
end

#child_value(name) ⇒ Object


16
17
18
19
20
21
22
# File 'app/models/caboose/block_cache.rb', line 16

def child_value(name)
  b = self.child(name)
  return nil if b.nil? 
  return b.image if b.block_type_field_type == 'image'
  return b.file  if b.block_type_field_type == 'file'
  return b.value
end

#children_where(h) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/caboose/block_cache.rb', line 31

def children_where(h)
  arr = []      
  self.children.each do |b|
    matches = true
    h.each do |k,v|
      if b.send(k) != v
        matches = false
        break
      end
    end
    arr << b if matches
  end
  return nil if arr.count == 0
  return arr
end

#marshal_dumpObject


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/caboose/block_cache.rb', line 70

def marshal_dump
  [
    self.id,
    self.page_id, 
    self.parent_id,
    self.block_type_id,
    self.block_type_field_type,
    self.sort_order,
    self.name,
    self.value,
    Marshal.dump(self.file),
    Marshal.dump(self.image),
    self.children.collect{ |b| Marshal.dump(b) }
  ]      
end

#marshal_load(array) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/caboose/block_cache.rb', line 86

def marshal_load array
  self.id,
  self.page_id, 
  self.parent_id,
  self.block_type_id,
  self.block_type_field_type,
  self.sort_order,
  self.name,
  self.value,
  self.file,
  self.image,
  self.children = array
  
  self.file = Marshal.load(self.file)
  self.image = Marshal.load(self.image)
  self.children = self.children.collect{ |kid| Marshal.load(kid) }
end

#pageObject


66
67
68
# File 'app/models/caboose/block_cache.rb', line 66

def page            
  return $page
end