Class: Evey::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Evey::Event
- Includes:
- Kix::Serializable
- Defined in:
- lib/evey/event.rb
Class Method Summary collapse
- .aggregates(*ags) ⇒ Object (also: aggregate)
- .associations(*assoces) ⇒ Object (also: association)
- .data_attributes(*attrs) ⇒ Object
-
.event_name ⇒ Object
Underscored class name by default.
- .inherited(klass) ⇒ Object
- .registered_events ⇒ Object
- .request_hook(&block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.aggregates(*ags) ⇒ Object Also known as: aggregate
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/evey/event.rb', line 23 def aggregates(*ags) @aggregates ||= [] ags.map(&:to_s).each do |ag| next if @aggregates.include?(ag) @aggregates << ag define_method ag do self.aggregates ||= {} self.aggregates[ag] end define_method "#{ag}=" do |arg| self.aggregates ||= {} self.aggregates[ag] = arg end end @aggregates end |
.associations(*assoces) ⇒ Object Also known as: association
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/evey/event.rb', line 46 def associations(*assoces) @associations ||= [] assoces.map(&:to_s).each do |assoc| next if @associations.include?(assoc) @associations << assoc define_method assoc do self.associations ||= {} self.associations[assoc] end define_method "#{assoc}=" do |arg| self.associations ||= {} self.associations[assoc] = arg end end @associations end |
.data_attributes(*attrs) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/evey/event.rb', line 69 def data_attributes(*attrs) @data_attributes ||= [] attrs.map(&:to_s).each do |attr| @data_attributes << attr unless @data_attributes.include?(attr) define_method attr do self.data ||= {} self.data[attr] end define_method "#{attr}=" do |arg| self.data ||= {} self.data[attr] = arg end define_method "#{attr}_was_set?" do self.data ||= {} self.data.key?(attr) end end @data_attributes end |
.event_name ⇒ Object
Underscored class name by default. ex: “post/updated” Used when sending events to the data pipeline
101 102 103 |
# File 'lib/evey/event.rb', line 101 def event_name name.underscore end |
.inherited(klass) ⇒ Object
17 18 19 20 21 |
# File 'lib/evey/event.rb', line 17 def inherited(klass) super ::Evey::Event.registered_events[klass.event_name] = klass klass.request_hook(&@request_hook) if @request_hook end |
.registered_events ⇒ Object
13 14 15 |
# File 'lib/evey/event.rb', line 13 def registered_events @registered_events ||= {} end |
.request_hook(&block) ⇒ Object
94 95 96 97 |
# File 'lib/evey/event.rb', line 94 def request_hook(&block) @request_hook = block if block.present? @request_hook end |
Instance Method Details
#apply ⇒ Object
116 117 |
# File 'lib/evey/event.rb', line 116 def apply end |
#errors_as_json ⇒ Object
123 124 125 126 127 |
# File 'lib/evey/event.rb', line 123 def errors_as_json return {} if errors.blank? errors.as_json.merge(aggregate_errors_as_json) end |
#request_hook ⇒ Object
119 120 121 |
# File 'lib/evey/event.rb', line 119 def request_hook self.class.request_hook end |