class Realm::Event
Constants
- T
Public Class Methods
flatten_attributes_meta()
click to toggle source
# File lib/realm/event.rb, line 40 def flatten_attributes_meta @flatten_attributes_meta ||= collect_attributes_meta(schema.key(:body).type) end
new(attributes = {})
click to toggle source
Calls superclass method
# File lib/realm/event.rb, line 24 def new(attributes = {}) head = { id: SecureRandom.uuid, correlation_id: SecureRandom.uuid, triggered_at: Time.now, version: 1, # until we need breaking change (anything except adding attribute) all events are version 1 }.merge(attributes.fetch(:head, {})) body = attributes[:body] || attributes.except(:head) super({ head: head }.merge(body.empty? ? {} : { body: body })) end
type(value = :not_provided)
click to toggle source
# File lib/realm/event.rb, line 35 def type(value = :not_provided) @type = value unless value == :not_provided @type ||= name.demodulize.sub('Event', '').underscore end
Protected Class Methods
body_struct(type = Dry::Core::Constants::Undefined, &block)
click to toggle source
# File lib/realm/event.rb, line 46 def body_struct(type = Dry::Core::Constants::Undefined, &block) attribute(:body, type, &block) end
Private Class Methods
collect_attributes_meta(thing, path = [])
click to toggle source
# File lib/realm/event.rb, line 52 def collect_attributes_meta(thing, path = []) # rubocop:disable Metrics/AbcSize if thing.respond_to?(:schema) && thing.constructor_type != Dry::Types::Hash::Constructor # struct thing.schema.keys.reduce({}) do |memo, key| memo.merge(collect_attributes_meta(key.type, path + [key.name])) end elsif thing.constructor_type == Dry::Types::Array::Constructor # array collect_attributes_meta(thing.type.member, path + [:[]]) else thing.meta.present? ? { path => thing.meta } : {} end end
Public Instance Methods
to_json(*args)
click to toggle source
# File lib/realm/event.rb, line 69 def to_json(*args) JSON.generate(to_h, *args) end
type()
click to toggle source
# File lib/realm/event.rb, line 65 def type self.class.type end