Skip to content

Instantly share code, notes, and snippets.

@AMHOL
Created July 9, 2019 01:50
Show Gist options
  • Save AMHOL/b95f55331c114c8e48e51121392d0115 to your computer and use it in GitHub Desktop.
Save AMHOL/b95f55331c114c8e48e51121392d0115 to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rom'
gem 'rom-http'
end
require 'rom'
rom = ROM.container(:http, uri: 'https://api.github.com', handlers: :json) do |config|
config.relation(:orgs) do
schema do
attribute :id, ROM::HTTP::Types::Integer
attribute :name, ROM::HTTP::Types::String
attribute :created_at, ROM::HTTP::Types::Params::Time
attribute :updated_at, ROM::HTTP::Types::Params::Time
end
def by_name(name)
append_path(name)
end
end
end
orgs = rom.relations[:orgs]
orgs.by_name('rom-rb').one
orgs.with(auto_struct: true).by_name('rom-rb').one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment