Module: Eventsimple::Entity::InstanceMethods

Defined in:
lib/eventsimple/entity.rb

Instance Method Summary collapse

Instance Method Details

#enable_writes!(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/eventsimple/entity.rb', line 37

def enable_writes!(&block)
  was_readonly = @readonly
  @readonly = false

  if block
    yield self
    @readonly = true if was_readonly
  end
end

#projection_matches_events?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/eventsimple/entity.rb', line 31

def projection_matches_events?
  reprojected = self.class.find(id).reproject

  attributes == reprojected.attributes
end

#reproject(at: nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/eventsimple/entity.rb', line 47

def reproject(at: nil)
  event_history = at ? events.where('created_at <= ?', at).load : events.load
  ignore_props = (DEFAULT_IGNORE_PROPS + ignored_for_projection).map(&:to_s)
  assign_attributes(self.class.column_defaults.except(*ignore_props))

  event_history.each do |event|
    event.apply_timestamps(self)
    event.apply(self)
  end

  self
end