Class: Tempo::Views::ViewRecords::Model

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

Overview

Base model class, used for extending views for any child of Tempo::Model::Base Sets the id, and type, where type is the class type of the model, for example “project” for Tempo::Model::Project. ViewReord::Model should handle any type of tempo model without error, but most likely won’t be as useful as a child class taylored to the specifics of the actual model’s child class.

Containers send :pospone => true in options in order to manage triggering the message themselves

Direct Known Subclasses

Composite, Log

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Model.



129
130
131
132
133
134
135
# File 'lib/tempo/views/view_records/base.rb', line 129

def initialize(model, options={})
  @id = model.id

  # example: Tempo::Model::Something => "something"
  @type = /Tempo::Model::(.*)$/.match( model.class.to_s )[1].downcase
  Reporter.add_view_record self unless options[:postpone]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



127
128
129
# File 'lib/tempo/views/view_records/base.rb', line 127

def id
  @id
end

#typeObject

Returns the value of attribute type.



127
128
129
# File 'lib/tempo/views/view_records/base.rb', line 127

def type
  @type
end

Instance Method Details

#format(&block) ⇒ Object



137
138
139
140
# File 'lib/tempo/views/view_records/base.rb', line 137

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