Git Product home page Git Product logo

mongoid-gitifield's Introduction

mongoid-gitifield

Mongoid-gitifield provides version control on your mongoid document field with git (the real git), gitify your field. Facilitating features from git to keep track on your changes, diff from versions and ability to update the value by applying patch. This gem stores a git repositroy (seriously) for each field you keep track on, encoded and stored within your document. It is not suitable for use cases that require search on changes or index.

Install

Add this to your Gemfile

gem 'mongoid-gitifield', git: 'https://github.com/Seitk/mongoid-gitifield.git'

And then run bundle install.

Usage

# app/models/post.rb
class Post
  include Mongoid::Document
  include Mongoid::Gitifield

  field :summary, type: String
  field :content, type: String

  # Specify fields to track
  gitifields_on   %i(summary content)
end

After that, gitifield workspace is generated for each field giving you access to the field repository XXXX_gitifield. Also when a document is created or updated, the gem will automatically commit new value to the field repository. Then the repositroy is pack in gziped tar, base64 encoded and save back into attributes with key XXXX_gitifield_data.

# Generated interface
post.summary_gitifield
post.content_gitifield

# Raw data stored in attributes
post[:summary_gitifield_data]
post[:content_gitifield_data]

Feature

# Get commit sha of current value
post.summary_gitifield.id

# Accessing current value of the field repository
post.summary_gitifield.content

# Update the value and commit right a way
post.summary_gitifield.update('<article><h1>Breaking News: Your cat can pick up on how you are feeling</h1></article>')

# Show commit logs
post.summary_gitifield.logs
# => [
#      {:id=>"8a78ab758b352e12cfc72a4a26ed0750c588006d", :date=>2017-09-30 11:02:16 +0000},
#      {:id=>"7df66c7f6d786699a7a972163aa70daaf406380c", :date=>2017-09-30 10:30:08 +0000},
#      {:id=>"0ce3a1ec9b46c892a714647dd3971e3dc1558fd0", :date=>2017-09-30 10:05:23 +0000},
#      {:id=>"8cba3b0a7a5d97a7081b12d1b2438b20258d01d8", :date=>2017-09-30 10:00:44 +0000}
#    ]

# Checkout to a specific commit
post.summary_gitifield.checkout('8a78ab758b352e12cfc72a4a26ed0750c588006d')

# Revert to a commit (we don't change history, it creates a new commit with the value instead)
post.summary_gitifield.revert('0ce3a1ec9b46c892a714647dd3971e3dc1558fd0')

# Apply patch from file
post.summary_gitifield.apply_patch(Dir.tmpdir.join('patch_001.diff'))

# Also, you can directly access to the git repository (thanks to ruby-git gem)
post.summary_gitifield.git
post.summary_gitifield.git.status

That is how it looks if you check the repository Alt text

Contributing to this project

Pull requests, feature requests and issue reportings are alwasy welcome and greatly appreciated.

Copyright

MIT License. See LICENSE for further details.

mongoid-gitifield's People

Contributors

seitk avatar

Watchers

 avatar  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.