Class: Tempo::Views::ViewRecords::Composite
- 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
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
- #format(&block) ⇒ Object
-
#initialize(model, options = {}) ⇒ Composite
constructor
A new instance of Composite.
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, ={}) super model, @depth = .fetch(:depth, 0) self.class.max_depth @depth end |
Instance Attribute Details
#depth ⇒ Object
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 |