Closed orien closed 7 years ago
Looks good. We just need to add some equality methods (I know some specs in Identity will fail without #==
, #eql?
etc). Here's what Virtus is adding in:
irb(main):013:0> puts EventSourcery::Event.new.method(:==).source
def ==(other)
other = coerce(other).first if respond_to?(:coerce, true)
other.kind_of?(self.class) && cmp?(__method__, other)
end
=> nil
irb(main):014:0> puts EventSourcery::Event.new.method(:eql?).source
def eql?(other)
instance_of?(other.class) && cmp?(__method__, other)
end
=> nil
irb(main):015:0> puts EventSourcery::Event.new.method(:cmp?).source
define_method(:cmp?) do |comparator, other|
keys.all? do |key|
__send__(key).public_send(comparator, other.__send__(key))
end
end
=> nil
Thanks @stevehodgkiss. I was going to ask about those.
Seems strange to inspect all attributes of an object which has specific identifier attributes.
I propose using id
for ordering comparisons, <
, <=
, ==
, >=
, >
. Whereas the eql?
method can use uuid
and instance type for its comparison.
@stevehodgkiss Will this satisfy Identity's use case?
I used a Ruby feature introduced in 2.3.0. Ok to lock EventSourcery to Ruby 2.3.0 or higher?
Convert
Event
to a plain old Ruby object. This was the only thing using Virtus, so we can now remove it as a dependency.