Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to make Guacamole

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

How to make Guacamole

This is my talk about the guacamole gem I gave at the local Ruby user group in Cologne. Guacamole is an ODM for ArangoDB. The talk is a general introduction to the gem and focuses on the design process and tooling. A short introduction into data source patterns is also present.

Hope you like it.

Dirk Breuer

April 17, 2014

Transcript

50 slides
  1. Implement a Data Source Pattern for a Multi-Model NoSQL database

    or How to make Guacamole 16.4.2014 / cologne.rb / @mixxt Dirk Breuer / @railsbros_dirk
  2. Data Source Pattern Architectural patterns which drive the way in

    which the domain logic talks to the database. – Martin Fowler
  3. NoSQL Not ACID compliant Big Data Distributed Web Scale ROFL

    Scale CAP Documents Flexible High Availability
  4. NoSQL Databases • „Not only SQL“ • Not one definition

    • Sometimes just a marketing buzz-fuzz
  5. gem 'guacamole' An ODM for ArangoDB to be used with

    Rails and other Ruby frameworks* Object Document Mapper *which is not yet finished
  6. Why should I use
 ArangoDB in favor of
 <any other

    document store>? With ArangoDB you can perform joins
 over your documents similar
 to joins in relational databases.
  7. 1 Design Goal 1 Data Source Pattern 3 Supporting Libraries

    1 Database driver 1 solid Test-Suite 1 Documentation
  8. Design Goal • Support building web applications with Ruby on

    Rails or other Rack-based frameworks • Focus on easy integration in Views and the general workflow • Reflect the nature of NoSQL in general and ArangoDB in particular
  9. + Testability is increased + Separation of Concern + Easier

    to support database
 features like embedded objects - The average Rails dev is
 used to Active Record - Starting with Data Mapper
 requires more effort
  10. The Model class Post include Guacamole::Model ! attribute :title, String

    attribute :body, String attribute :comments, Array[Comment] attribute :user, User end
  11. „Ensures that each object gets loaded only once by keeping

    every loaded object in a map. Looks up objects using the map when referring to them.“ – Martin Fowler
  12. • Not a Cache! • Every session needs its own,

    fresh instance • Should be suited for concurrency (you know, just in case)
  13. module Guacamole class IdentityMap class << self def store(object) @_map

    = _map.put(key_for(object), object) object end ! def retrieve(klass, key) _map.get key_for(klass, key) end ! def _map @_map ||= Hamster.hash end end end end
  14. • Really useful, not only for Rails • A lot

    of Gems build on top of Active Model • A lot of useful features (i.e. Validations) • Not related to the Active Record pattern
  15. class Author extend ActiveSupport::Autoload include Guacamole::Model ! autoload :Book, 'models/book'

    ! attribute :name, String attribute :books, Array[Book] end class Book extend ActiveSupport::Autoload include Guacamole::Model ! autoload :Author, 'models/author' ! attribute :title, String attribute :author, Author end This is not very Ruby

More Decks by Dirk Breuer

Other Decks in Programming