Giter Club home page Giter Club logo

rom's Introduction

Ruby Object Mapper

Gem Version Build Status Dependency Status Code Climate Test Coverage Inline docs

Ruby Object Mapper (ROM) is an experimental Ruby library with the goal to provide powerful object mapping capabilities without limiting the full power of your datastore.

Learn more:

Adapters

See issues for a list of adapters that are planned to be added soon.

ROM can be used with Rails next to ActiveRecord via rom-rails railtie. Integration with other frameworks is planned.

Synopsis

ROM.setup(:memory)

# This is our domain-specific class
class User
  attr_reader :name, :age

  def initialize(attributes)
    @name, @age = attributes.values_at(:name, :age)
  end
end

# Here we define user relation which encapsulates accessing user data that
# we can map to domain objects
class Users < ROM::Relation[:memory]
  def by_name(name)
    restrict(name: name)
  end

  def adults
    find_all { |user| user[:age] >= 18 }
  end
end

# Even though mappers can be derived from model definitions here's how you
# could define it explicitly
class UserMapper < ROM::Mapper
  relation :users

  model User

  attribute :name
  attribute :age
end

# You can define specialized commands that handle creating, updating and deleting
# data, those classes can use external input param handlers and validators too
class CreateUser < ROM::Commands::Create[:memory]
  register_as :create
  relation :users
  result :one
end

# finalize the setup and retrieve object registry (aka ROM env)
rom = ROM.finalize.env

# accessing defined commands
rom.command(:users).create.call(name: "Joe", age: 17)
rom.command(:users).create.call(name: "Joe", age: 17)

# reading relations using defined mappers
puts rom.read(:users).by_name("Jane").adults.to_a.inspect
# => [#<User:0x007fdba161cc48 @id=2, @name="Jane", @age=18>]

ROADMAP

ROM is on its way towards 1.0.0. Please refer to issues for details.

Community

Credits

This project has a long history and wouldn't exist without following people:

License

See LICENSE file.

rom's People

Contributors

solnic avatar snusnu avatar splattael avatar chastell avatar aflatter avatar mbj avatar mcls avatar cored avatar plexus avatar dkubb avatar dreoliv avatar elskwid avatar gotar avatar billdueber avatar rrrene avatar adz avatar myabc avatar antoinelyset avatar olefine avatar lasseebert avatar hakon avatar indrekj avatar jeremyf avatar jgeiger avatar kchien avatar ovargas27 avatar locks avatar rolfb avatar senny avatar namusyaka avatar

Watchers

Rui Santos avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.