Skip to content

Instantly share code, notes, and snippets.

@ginjo
Created March 24, 2015 23:34
Show Gist options
  • Select an option

  • Save ginjo/a399ca8a146ca6159451 to your computer and use it in GitHub Desktop.

Select an option

Save ginjo/a399ca8a146ca6159451 to your computer and use it in GitHub Desktop.
ROM swappable datastore example
# Swappable datastore example
ROM_ADAPTER = :sql # or :memory
# ...setup
class UsersSql < ROM::Relation[:sql]
dataset :users
def by_name(name)
where(name: name)
end
end if ROM_ADAPTER == :sql
class UsersMemory < ROM::Relation[:memory]
dataset :users
def by_name(name)
restrict(name: name)
end
end if ROM_ADAPTER == :memory
# ...finalize
@users = ROM.env.relation(:users)
@users.by_name('bill')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment