mm-versionable 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +51 -47
 - data/lib/versionable/plugins/versionable.rb +1 -1
 - data/lib/versionable/version.rb +1 -1
 - data/test/test_helper.rb +1 -1
 - metadata +2 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -18,73 +18,77 @@ Usage 
     | 
|
| 
       18 
18 
     | 
    
         
             
            -----
         
     | 
| 
       19 
19 
     | 
    
         
             
            The following example should demonstrate how to use versioning well :
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
                require 'mongo_mapper'
         
     | 
| 
      
 22 
     | 
    
         
            +
                require 'config'  # Since versionable defines it's own Version model and has a few indexes defined for the same, 
         
     | 
| 
      
 23 
     | 
    
         
            +
                                  # we need to load & configure mongo_mapper before we can load versionable.
         
     | 
| 
      
 24 
     | 
    
         
            +
                require 'versionable' 
         
     | 
| 
      
 25 
     | 
    
         
            +
                # gem 'mm-versionable', :require => 'versionable' -- Put this in your Gemfile if you're using bundler
         
     | 
| 
       24 
26 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              #By default, if not specified, the value is 10, if you wish to load all versions set it to 0
         
     | 
| 
      
 27 
     | 
    
         
            +
                class Thing
         
     | 
| 
      
 28 
     | 
    
         
            +
                    include MongoMapper::Document
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                    enable_versioning :limit => 20
         
     | 
| 
      
 31 
     | 
    
         
            +
                    #:limit here defines the size of the version history that will be loaded into memory,
         
     | 
| 
      
 32 
     | 
    
         
            +
                    #By default, if not specified, the value is 10, if you wish to load all versions set it to 0
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
                    key :name, String, :required => true
         
     | 
| 
      
 35 
     | 
    
         
            +
                    key :date, Time
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
       34 
37 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
            thing.name  
     | 
| 
       36 
     | 
    
         
            -
            thing.save
         
     | 
| 
      
 38 
     | 
    
         
            +
                thing = Thing.create(:name => 'Dhruva Sagar', :date => Time.now)
         
     | 
| 
       37 
39 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
            #thing.save :updater_id => "4cef9936f61aa33717000001"
         
     | 
| 
      
 40 
     | 
    
         
            +
                thing.name = 'Change Thing'
         
     | 
| 
      
 41 
     | 
    
         
            +
                thing.save
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 43 
     | 
    
         
            +
                #Alternatively you can also pass in a "updater_id" to the save method which will be saved within the version, this can be used to track who made changes
         
     | 
| 
      
 44 
     | 
    
         
            +
                #example :
         
     | 
| 
      
 45 
     | 
    
         
            +
                #thing.save :updater_id => "4cef9936f61aa33717000001"
         
     | 
| 
       44 
46 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
            thing. 
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                thing.versions_count 
         
     | 
| 
      
 48 
     | 
    
         
            +
                #=> 2
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
            thing. 
     | 
| 
       49 
     | 
    
         
            -
            #=> #< 
     | 
| 
      
 50 
     | 
    
         
            +
                thing.versions
         
     | 
| 
      
 51 
     | 
    
         
            +
                #=> [#<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>, #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>]
         
     | 
| 
       50 
52 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
            thing. 
     | 
| 
       52 
     | 
    
         
            -
            #=> #< 
     | 
| 
      
 53 
     | 
    
         
            +
                thing.all_versions
         
     | 
| 
      
 54 
     | 
    
         
            +
                #=> #<Plucky::Query doc_id: "4cef96c4f61aa33621000001", sort: [["pos", -1]]> 
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
            thing.rollback(: 
     | 
| 
       55 
     | 
    
         
            -
            #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
         
     | 
| 
      
 56 
     | 
    
         
            +
                thing.rollback(:first)
         
     | 
| 
      
 57 
     | 
    
         
            +
                #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
            thing.rollback 
     | 
| 
       58 
     | 
    
         
            -
            #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number:  
     | 
| 
       59 
     | 
    
         
            -
            #rollback! saves the document as well
         
     | 
| 
      
 59 
     | 
    
         
            +
                thing.rollback(:last)
         
     | 
| 
      
 60 
     | 
    
         
            +
                #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 0, name: "Dhruva Sagar", date: 2010-11-26 11:15:16 UTC>
         
     | 
| 
       60 
61 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
            thing. 
     | 
| 
       62 
     | 
    
         
            -
            #=>  
     | 
| 
      
 62 
     | 
    
         
            +
                thing.rollback!(:latest)
         
     | 
| 
      
 63 
     | 
    
         
            +
                #=> #<Thing _id: BSON::ObjectId('4cef96c4f61aa33621000001'), version_message: nil, version_number: 1, name: "Change Thing", date: 2010-11-26 11:15:16 UTC>
         
     | 
| 
      
 64 
     | 
    
         
            +
                #rollback! saves the document as well
         
     | 
| 
       63 
65 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
            thing.diff(:name, 0, 1 
     | 
| 
       65 
     | 
    
         
            -
            #=> " 
     | 
| 
      
 66 
     | 
    
         
            +
                thing.diff(:name, 0, 1)
         
     | 
| 
      
 67 
     | 
    
         
            +
                #=> "<del class=\"differ\">Change</del><ins class=\"differ\">Dhruva</ins> <del class=\"differ\">Thing</del><ins class=\"differ\">Sagar</ins>"
         
     | 
| 
       66 
68 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
            thing.diff(:name, 0, 1, : 
     | 
| 
       68 
     | 
    
         
            -
            #=> " 
     | 
| 
      
 69 
     | 
    
         
            +
                thing.diff(:name, 0, 1, :ascii)
         
     | 
| 
      
 70 
     | 
    
         
            +
                #=> "{\"Change\" >> \"Dhruva\"} {\"Thing\" >> \"Sagar\"}"
         
     | 
| 
       69 
71 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
            thing. 
     | 
| 
       71 
     | 
    
         
            -
            #=>  
     | 
| 
      
 72 
     | 
    
         
            +
                thing.diff(:name, 0, 1, :color)
         
     | 
| 
      
 73 
     | 
    
         
            +
                #=> "\e[31mChange\e[0m\e[32mDhruva\e[0m \e[31mThing\e[0m\e[32mSagar\e[0m"
         
     | 
| 
       72 
74 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
            thing. 
     | 
| 
       74 
     | 
    
         
            -
            #=> #<Version _id: BSON::ObjectId(' 
     | 
| 
      
 75 
     | 
    
         
            +
                thing.current_version
         
     | 
| 
      
 76 
     | 
    
         
            +
                #=> #<Version _id: BSON::ObjectId('4cf03822f61aa30fd8000004'), data: {"_id"=>BSON::ObjectId('4cf03816f61aa30fd8000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 22:43:34 UTC}, date: 2010-11-26 22:43:46 UTC, pos: nil, doc_id: "4cf03816f61aa30fd8000001", message: nil, updater_id: nil>
         
     | 
| 
       75 
77 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
            thing.version_at(: 
     | 
| 
       77 
     | 
    
         
            -
            #=> #<Version _id: BSON::ObjectId(' 
     | 
| 
      
 78 
     | 
    
         
            +
                thing.version_at(:first)
         
     | 
| 
      
 79 
     | 
    
         
            +
                #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
         
     | 
| 
       78 
80 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
            thing.version_at(: 
     | 
| 
       80 
     | 
    
         
            -
            #=> #<Version _id: BSON::ObjectId(' 
     | 
| 
      
 81 
     | 
    
         
            +
                thing.version_at(:current)
         
     | 
| 
      
 82 
     | 
    
         
            +
                #=> #<Version _id: BSON::ObjectId('4cef986df61aa33621000004'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>1, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:22:21 UTC, pos: nil, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
         
     | 
| 
       81 
83 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
            thing.version_at(: 
     | 
| 
       83 
     | 
    
         
            -
            #=> #<Version _id: BSON::ObjectId(' 
     | 
| 
      
 84 
     | 
    
         
            +
                thing.version_at(:last)
         
     | 
| 
      
 85 
     | 
    
         
            +
                #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000002'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Dhruva Sagar", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 0, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil>
         
     | 
| 
       84 
86 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
            thing.version_at( 
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
                thing.version_at(:latest)
         
     | 
| 
      
 88 
     | 
    
         
            +
                #=> #<Version _id: BSON::ObjectId('4cef96c4f61aa33621000003'), data: {"_id"=>BSON::ObjectId('4cef96c4f61aa33621000001'), "version_message"=>nil, "version_number"=>nil, "name"=>"Change Thing", "date"=>2010-11-26 11:15:16 UTC}, date: 2010-11-26 11:15:16 UTC, pos: 1, doc_id: "4cef96c4f61aa33621000001", message: nil, updater_id: nil> 
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                thing.version_at(10)
         
     | 
| 
      
 91 
     | 
    
         
            +
                #=> nil
         
     | 
| 
       88 
92 
     | 
    
         | 
| 
       89 
93 
     | 
    
         
             
            Problems or Questions?
         
     | 
| 
       90 
94 
     | 
    
         
             
            ----------------------
         
     | 
    
        data/lib/versionable/version.rb
    CHANGED
    
    
    
        data/test/test_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: mm-versionable
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.2.5
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Dhruva Sagar
         
     | 
| 
         @@ -10,7 +10,7 @@ autorequire: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            date: 2011-06- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2011-06-18 00:00:00 +05:30
         
     | 
| 
       14 
14 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |