Module: Polo

Defined in:
lib/polo.rb,
lib/polo/version.rb,
lib/polo/collector.rb,
lib/polo/translator.rb,
lib/polo/configuration.rb,
lib/polo/sql_translator.rb

Defined Under Namespace

Classes: Collector, Configuration, SqlTranslator, Translator, Traveler

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object

Public: Sets up global settings for Polo

block - Takes a block with the settings you decide to use

obfuscate - Takes a blacklist with sensitive fields you wish to scramble
on_duplicate - Defines the on_duplicate strategy for your INSERTS
  e.g. :override, :ignore

usage:

Polo.configure do
  obfuscate(:email, :password, :credit_card)
  on_duplicate(:override)
end


59
60
61
62
63
# File 'lib/polo.rb', line 59

def self.configure(&block)
  @configuration = Configuration.new
  @configuration.instance_eval(&block) if block_given?
  @configuration
end

.defaultsObject

Public: Returns the default settings



67
68
69
# File 'lib/polo.rb', line 67

def self.defaults
  @configuration || configure
end

.explore(base_class, id, dependencies = {}) ⇒ Object

Public: Traverses a dependency graph based on a seed ActiveRecord object and generates all the necessary INSERT queries for each one of the records it finds along the way.

base_class - An ActiveRecord::Base class for the seed record. id - An ID used to find the desired seed record.

dependency_tree - An ActiveRecord::Associations::Preloader compliant that will define the path Polo will traverse.

(from ActiveRecord::Associations::Preloader docs) It may be:

  • a Symbol or a String which specifies a single association name. For example, specifying :books allows this method to preload all books for an Author.

  • an Array which specifies multiple association names. This array is processed recursively. For example, specifying [:avatar, :books] allows this method to preload an author’s avatar as well as all of his books.

  • a Hash which specifies multiple association names, as well as association names for the to-be-preloaded association objects. For example, specifying { author: :avatar } will preload a book’s author, as well as that author’s avatar.

:associations has the same format as the :include option for ActiveRecord::Base.find. So associations could look like this:

:books
[ :books, :author ]
{ author: :avatar }
[ :books, { author: :avatar } ]


40
41
42
# File 'lib/polo.rb', line 40

def self.explore(base_class, id, dependencies={})
  Traveler.collect(base_class, id, dependencies).translate(defaults)
end