Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Seitk/mongoid-gitifield
Git version control on mongoid document
https://github.com/Seitk/mongoid-gitifield
Last synced: about 1 month ago
JSON representation
Git version control on mongoid document
- Host: GitHub
- URL: https://github.com/Seitk/mongoid-gitifield
- Owner: Seitk
- License: mit
- Created: 2017-09-29T07:11:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T09:03:44.000Z (almost 2 years ago)
- Last Synced: 2024-06-26T18:58:07.703Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 6.84 KB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-hk-open-source - mongoid-gitifield - 令 Mongoid field 可以以 git repository 方式來做 version control。[![GitHub stars](https://img.shields.io/github/stars/Seitk/mongoid-gitifield.svg?style=social)](https://github.com/Seitk/mongoid-gitifield/stargazers) (Ruby)
README
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`
```ruby
gem 'mongoid-gitifield', git: 'https://github.com/Seitk/mongoid-gitifield.git'
```And then run `bundle install`.
Usage
-----```ruby
# app/models/post.rb
class Post
include Mongoid::Document
include Mongoid::Gitifieldfield :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`.
```ruby
# Generated interface
post.summary_gitifield
post.content_gitifield# Raw data stored in attributes
post[:summary_gitifield_data]
post[:content_gitifield_data]
```Feature
-------```ruby
# 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('Breaking News: Your cat can pick up on how you are feeling
')# 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](https://storage.googleapis.com/philip-test/gitifield.png "The field repository")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.