GithubHelp home page GithubHelp logo

laforge's Introduction

LaForge Gem Version

By Combinaut.

LaForge is a gem that makes it easy to build records using data from several data sources. It aims to facilitate management of which data sources a record is assembled from, and to perform the actual data assembly in order to output a record.

Key features:

  • Allows published content to be edited without those changes immediately being seen by visitors
  • Can selectively update content without needing to sync the entire database with production

Setup

  1. Add Laforge to your Gemfile:
gem 'laforge', github: 'combinaut/laforge'
  1. Add laforge to your model.
  # In your model
  class MyModel < ApplicationModel
    laforged
  end

Usage

  1. Create some sources and prioritize them, giving higher priority to sources whose attributes should override those same attributes from lower priority sources.
  source1 = LaForge::DataSource.create(name: 'Encyclopedia Britannica', priority: 2)
  source2 = LaForge::DataSource.create(name: 'Wikipedia', priority: 1)
  1. Build a new model, or update an existing one with data from any of your sources.
  foo = MyModel.new
  foo.record_data_entries({ height: 20, width: 5 }, source1)
  foo.record_data_entries({ height: 19, name: 'El Capitan' }, source2)
  foo.forge! # => Saves the model with the attributes { height: 20, width: 5, name: 'El Capitan' }

Note: Calling record_data_entries builds the Data Entries, but they are not persisted and and the record's attributes not updated until forge! is called.

  1. Remove data for an existing model from any of your sources.
  foo.remove_data_entries(source1)
  foo.forge! # => Saves the model with the attributes { height: 19, width: nil, name: 'El Capitan' }

Note: calling remove_data_entries marks the Data Entries for destruction, but they are not destroyed and the removed attributes not nullified until forge! is called.

Overriding Priority

The priority of a data entry can be customized to override the priority inherited from the data source.

  foo = MyModel.new
  foo.record_data_entries({ height: 20, width: 5 }, source1)
  foo.record_data_entries({ height: 19 }, source2, priority: 3) # Override the priority inherited from the data source
  foo.forge! # => Saves the model with the attributes { height: 19, width: 5 }

Querying

  MyModel.with_source(source1) # => All records from source1
  MyModel.without_source(source1) # => All records not from source1

  MyModel.with_attribute(:height) # => All records with a recorded height attribute from any source
  MyModel.without_attribute(:height) # => All records without a recorded height attribute from any source

  MyModel.with_attribute_with_source(:height, source1) # => All records with a recorded height attribute from source1
  MyModel.with_attribute_with_source([:height, :width], source1) # => All records with a recorded height or width attribute from source1

  MyModel.with_attribute_without_source(:height, source1) # => All records with a recorded height not from source1
  MyModel.with_attribute_without_source([:height, :width], source1) # => All records with a recorded height or width attribute not from source1
  MyModel.with_attribute_with_source(:height, source1).with_attribute_with_source(:width, source1) # => All records with both a recorded height and width attribute from source1

  MyModel.without_attribute_with_source(:height, source1) # => All records without a recorded height attribute from source1
  MyModel.without_attribute_with_source([:height, :width], source1) # => All records missing a recorded height or missing a recorded width from source1
  MyModel.without_attribute_with_source(:height, source1).without_attribute_with_source(:width, source1) # => All records without both a recorded height and width attribute from source1

laforge's People

Contributors

clouie87 avatar njakobsen avatar

Watchers

Sebastian Friedrich avatar Ryan Wallace avatar Steffen Leistner avatar  avatar Nicholas Okuley avatar Tim Tait avatar James Cloos avatar Darren Walker avatar  avatar

Forkers

clouie87 bayornet

laforge's Issues

Add priority aliases

We don't want custom priorities on data entries to become a pain to manage like z-index. We can create aliases so instead of a number you pass the alias, and we can configure aliases all in one spot.

e.g.

address.forge! do
  address.record_data_entries(address_attributes_for(department), "Epic")
  address.record_data_entries(prioritized_address_attributes_for(department), "Epic", priority: 100)
end

would become

address.forge! do
  address.record_data_entries(address_attributes_for(department), "Epic")
  address.record_data_entries(prioritized_address_attributes_for(department), "Epic", priority: :highest)
end

Laforge.configuration do |config|
  config.priority_aliases = {
    highest: 100
  }
end

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.