Module: EventSourcedRecord::Event
- Includes:
- ActiveRecord::Immutable
- Defined in:
- lib/event_sourced_record/event.rb
Defined Under Namespace
Modules: ClassMethods
Classes: EventTypeConfig, EventTypeImmutableError
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/event_sourced_record/event.rb', line 59
def method_missing(meth, *args, &block)
if event_type_config && event_type_config.attributes.include?(meth)
ensure_data
self.data[meth.to_s]
elsif event_type_config && event_type_config.attributes.any? { |a| "#{a}=".to_sym == meth }
ensure_data
attr = meth.to_s.gsub(/=$/, '')
self.data[attr] = args.first
else
super
end
end
|
Class Method Details
.included(model) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/event_sourced_record/event.rb', line 6
def self.included(model)
model.cattr_accessor :_event_type_configs
model.extend ClassMethods
model.after_initialize :ensure_data
model.after_initialize :ensure_projection_uuid
model.after_initialize :lock_event_type
model.validates :event_type, presence: true
model.validate :validate_corrent_event_type
model.validate :validate_by_event_type
end
|
Instance Method Details
#event_type ⇒ Object
17
18
19
|
# File 'lib/event_sourced_record/event.rb', line 17
def event_type
attributes["event_type"]
end
|
#event_type=(value) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/event_sourced_record/event.rb', line 21
def event_type=(value)
if @event_type_locked
raise EventTypeImmutableError, "Event types can't be changed"
else
write_attribute(:event_type, value)
end
end
|
#respond_to?(meth, include_all = false) ⇒ Boolean
29
30
31
32
33
34
35
36
37
|
# File 'lib/event_sourced_record/event.rb', line 29
def respond_to?(meth, include_all = false)
if event_type_config && event_type_config.attributes.include?(meth)
true
elsif event_type_config && event_type_config.attributes.any? { |a| "#{a}=" == meth }
true
else
super
end
end
|