Last active
June 23, 2020 09:01
dry-Struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile(false) do | |
source "https://rubygems.org" | |
gem "dry-struct", '0.5' | |
gem "dry-types", '0.14' | |
gem 'rails_event_store-rspec', '1.0.0' | |
gem "pry-byebug" | |
gem 'activesupport' | |
end | |
require 'rspec/autorun' | |
require 'active_support/core_ext/object/try' | |
module Types | |
include Dry::Types.module | |
end | |
class Event < Dry::Struct | |
def data | |
to_h | |
end | |
def metadata | |
{} | |
end | |
end | |
class Address < Dry::Struct | |
attribute :name, Types::String.meta(omittable: true) | |
end | |
class MyEvent < Event | |
attribute :address, Address.meta(omittable: true) | |
end | |
RSpec.describe MyEvent do | |
it 'works' do | |
event = described_class.new(address: { name: 'foo' }) | |
expect(event) | |
.to(be_an_event(described_class) | |
.with_data(address: { name: 'foo' })) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment