Skip to content

Instantly share code, notes, and snippets.

@reedlaw
Created October 20, 2017 19:30
Show Gist options
  • Save reedlaw/67a5ee2c886afdcf44c63fb0dbe852f5 to your computer and use it in GitHub Desktop.
Save reedlaw/67a5ee2c886afdcf44c63fb0dbe852f5 to your computer and use it in GitHub Desktop.
ROM mapper issue
#!/usr/bin/ruby
require 'rom'
configuration = ROM::Configuration.new(:memory, 'memory://test')
class AppointmentInfoRepository < ROM::Repository::Root
root :appointment_info
commands :create
end
class AppointmentInfo < ROM::Relation[:memory]
schema do
attribute :date, Types::String, read: Types::Form::Date
end
end
class CreateAppointmentInfo < ROM::Commands::Create[:memory]
relation :appointment_info
register_as :create
result :one
end
class AppointmentMapper < ROM::Mapper
relation :appointment_info
register_as :appointment_mapper
end
class MyMapper < ROM::Mapper
relation :appointment_info
register_as :my_mapper
attribute(:date) { |t| t.strftime('%m/%d/%Y') }
attribute(:start_time, from: :time)
end
configuration.register_relation(AppointmentInfo)
configuration.register_command(CreateAppointmentInfo)
configuration.register_mapper(AppointmentMapper)
configuration.register_mapper(MyMapper)
container = ROM.container(configuration)
appt_info = container.relations[:appointment_info]
create_appt_info = appt_info.command(:create)
puts create_appt_info.call(date: Date.today).to_h
puts appt_info.map_with(:my_mapper).to_a
puts appt_info.map_with(:appointment_mapper).to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment