Class: Tempo::Views::ViewRecords::Composite

Inherits:
Model
  • Object
show all
Defined in:
lib/tempo/views/view_records/composite.rb

Overview

Base Composite model class, used for extending views for any child of Tempo::Model::Composite Inherits the id, and type from ViewRecords::Model, and adds an integer depth to hold the depth within the tree structure of the Composite model. It is important to note, the ViewRecord has no way of determining the depth of the model it represents, and this must be supplied to the instance on instantiation, or after.

The Composite ViewRecord class also keeps track of the max depth of all of it’s members, this can be used to calculate the padding added to any views.

The Composite View Model is an abstract model that is extended to create views for children of the Composite Model class. See ViewRecords::Project for an example.

Direct Known Subclasses

Project

Instance Attribute Summary collapse

Attributes inherited from Model

#id, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, options = {}) ⇒ Composite

Returns a new instance of Composite.



27
28
29
30
31
# File 'lib/tempo/views/view_records/composite.rb', line 27

def initialize(model, options={})
  super model, options
  @depth = options.fetch(:depth, 0)
  self.class.max_depth @depth
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



18
19
20
# File 'lib/tempo/views/view_records/composite.rb', line 18

def depth
  @depth
end

Class Method Details

.max_depth(depth = 0) ⇒ Object



21
22
23
24
# File 'lib/tempo/views/view_records/composite.rb', line 21

def max_depth(depth=0)
  @max_depth ||= 0
  @max_depth = @max_depth > depth ? @max_depth : depth
end

Instance Method Details

#format(&block) ⇒ Object



33
34
35
36
# File 'lib/tempo/views/view_records/composite.rb', line 33

def format(&block)
  block ||= lambda {|model| "#{"  " * model.depth}#{ model.type.capitalize} #{model.id}"}
  block.call self
end