Save 37% off PRO during our Black Friday Sale! »

How to make Guacamole

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


  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. • Active Record • Data Mapper
 • Table Data Gateway

    • Row Data Gateway • …
  4. NoSQL Not ACID compliant Big Data Distributed Web Scale ROFL

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

    • Sometimes just a marketing buzz-fuzz
  6. Classifications • Document-based • Key-Value stores • Graph-based • Column

    stores • Time series Aggregate-based }
  7. Multi-Model Combine more than one approach within one database system

  8. Guacamole Source: A dip consisting at least of ripe

    avocados and salt
  9. …and…

  10. gem 'guacamole' An ODM for ArangoDB to be used with

    Rails and other Ruby frameworks* Object Document Mapper *which is not yet finished
  11. • Open-Source NoSQL database • Multi-Model • Document-based • Graph-based

  12. 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.
  13. None
  14. Before you start

  15. Patterns of Enterprise Application Architecture

  16. Ingredients

  17. 1 Design Goal 1 Data Source Pattern 3 Supporting Libraries

    1 Database driver 1 solid Test-Suite 1 Documentation
  18. 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
  19. Data Source Pattern

  20. Data Mapper It’s a Nein! – Doch! – Ohhhh!

  21. + 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
  22. Supporting Libraries

  23. spec.add_dependency 'ashikawa-core' spec.add_dependency 'virtus' spec.add_dependency 'activemodel' spec.add_dependency 'hamster' spec.add_dependency 'activesupport'

  24. Implementation

  25. Just some bits and pieces…

  26. The Model class Post include Guacamole::Model ! attribute :title, String

    attribute :body, String attribute :comments, Array[Comment] attribute :user, User end
  27. The Collection (a.k.a. The Mapper) class PostsCollection include Guacamole::Collection !

    map do embeds :comments references :user end end
  28. ActiveRecord equivalent class Post < ActiveRecord belongs_to :user has_many :comments

  29. Retrieving Data # Get a user by email UsersCollection.by_example(email: "")

  30. Identity Map

  31. „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
  32. • Not a Cache! • Every session needs its own,

    fresh instance • Should be suited for concurrency (you know, just in case)
  33. 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
  34. Lazy Loading

  35. Post#user #<User> Proxy UsersCollection.by_key(post_document[:user_key])

  36. Active Model compliance

  37. • 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
  38. Caveats

  39. rom-rb/devtools

  40. None
  41. None
  42. Virtus and Circular Dependencies

  43. None
  44. 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
  45. Next Steps

  46. Support for Arango Query Language (AQL)

  47. Support for Transactions

  48. Support the Graph API

  49. Get a Nacho and dip in

  50. Thanks