plain_record 0.1 → 0.2
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/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/.yardopts +4 -0
- data/ChangeLog +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +3 -4
- data/README.md +124 -0
- data/Rakefile +27 -50
- data/lib/plain_record/association_proxy.rb +59 -0
- data/lib/plain_record/associations.rb +271 -0
- data/lib/plain_record/callbacks.rb +146 -0
- data/lib/plain_record/filepath.rb +141 -0
- data/lib/plain_record/model/entry.rb +17 -9
- data/lib/plain_record/model/list.rb +22 -9
- data/lib/plain_record/model.rb +119 -64
- data/lib/plain_record/resource.rb +72 -19
- data/lib/plain_record/version.rb +1 -1
- data/lib/plain_record.rb +21 -2
- data/plain_record.gemspec +30 -0
- data/spec/associations_spec.rb +142 -0
- data/spec/callbacks_spec.rb +59 -0
- data/spec/data/1/comments.yml +5 -0
- data/spec/data/1/{post.m → post.md} +0 -0
- data/spec/data/2/{post.m → post.md} +1 -1
- data/spec/data/3/post.md +4 -0
- data/spec/data/authors/extern.yml +2 -2
- data/spec/data/authors/intern.yml +4 -4
- data/spec/data/best/4/post.md +1 -0
- data/spec/filepath_spec.rb +53 -0
- data/spec/model_spec.rb +90 -42
- data/spec/resource_spec.rb +70 -27
- data/spec/spec_helper.rb +33 -14
- metadata +122 -70
- data/README.rdoc +0 -96
- data/spec/data/3/post.m +0 -1
    
        metadata
    CHANGED
    
    | @@ -1,93 +1,145 @@ | |
| 1 | 
            -
            --- !ruby/object:Gem::Specification | 
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: plain_record
         | 
| 3 | 
            -
            version: !ruby/object:Gem::Version | 
| 4 | 
            -
              version:  | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: '0.2'
         | 
| 5 | 
            +
              prerelease: 
         | 
| 5 6 | 
             
            platform: ruby
         | 
| 6 | 
            -
            authors: | 
| 7 | 
            +
            authors:
         | 
| 7 8 | 
             
            - Andrey "A.I." Sitnik
         | 
| 8 9 | 
             
            autorequire: 
         | 
| 9 10 | 
             
            bindir: bin
         | 
| 10 11 | 
             
            cert_chain: []
         | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 12 | 
            +
            date: 2012-05-18 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: bundler
         | 
| 16 | 
            +
              requirement: &17738960 !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ! '>='
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 1.0.10
         | 
| 22 | 
            +
              type: :development
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: *17738960
         | 
| 25 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 26 | 
            +
              name: yard
         | 
| 27 | 
            +
              requirement: &17738420 !ruby/object:Gem::Requirement
         | 
| 28 | 
            +
                none: false
         | 
| 29 | 
            +
                requirements:
         | 
| 30 | 
            +
                - - ! '>='
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '0'
         | 
| 33 | 
            +
              type: :development
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              version_requirements: *17738420
         | 
| 36 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 37 | 
            +
              name: rake
         | 
| 38 | 
            +
              requirement: &17737900 !ruby/object:Gem::Requirement
         | 
| 39 | 
            +
                none: false
         | 
| 40 | 
            +
                requirements:
         | 
| 41 | 
            +
                - - ! '>='
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 43 | 
            +
                    version: '0'
         | 
| 44 | 
            +
              type: :development
         | 
| 45 | 
            +
              prerelease: false
         | 
| 46 | 
            +
              version_requirements: *17737900
         | 
| 47 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 48 | 
            +
              name: rspec
         | 
| 49 | 
            +
              requirement: &17737420 !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                none: false
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ! '>='
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
              type: :development
         | 
| 56 | 
            +
              prerelease: false
         | 
| 57 | 
            +
              version_requirements: *17737420
         | 
| 58 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 59 | 
            +
              name: redcarpet
         | 
| 60 | 
            +
              requirement: &17736940 !ruby/object:Gem::Requirement
         | 
| 61 | 
            +
                none: false
         | 
| 62 | 
            +
                requirements:
         | 
| 63 | 
            +
                - - ! '>='
         | 
| 64 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 65 | 
            +
                    version: '0'
         | 
| 66 | 
            +
              type: :development
         | 
| 67 | 
            +
              prerelease: false
         | 
| 68 | 
            +
              version_requirements: *17736940
         | 
| 69 | 
            +
            description: ! "    Plain Record is a data persistence, which use human editable and\n
         | 
| 70 | 
            +
              \   readable plain text files. It’s ideal for static generated sites,\n    like
         | 
| 71 | 
            +
              blog or homepage.\n"
         | 
| 17 72 | 
             
            email: andrey@sitnik.ru
         | 
| 18 73 | 
             
            executables: []
         | 
| 19 | 
            -
             | 
| 20 74 | 
             
            extensions: []
         | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
            - README.rdoc
         | 
| 75 | 
            +
            extra_rdoc_files:
         | 
| 76 | 
            +
            - README.md
         | 
| 24 77 | 
             
            - LICENSE
         | 
| 25 | 
            -
             | 
| 78 | 
            +
            - ChangeLog
         | 
| 79 | 
            +
            files:
         | 
| 80 | 
            +
            - .gitignore
         | 
| 81 | 
            +
            - .rspec
         | 
| 82 | 
            +
            - .travis.yml
         | 
| 83 | 
            +
            - .yardopts
         | 
| 84 | 
            +
            - ChangeLog
         | 
| 85 | 
            +
            - Gemfile
         | 
| 86 | 
            +
            - Gemfile.lock
         | 
| 87 | 
            +
            - LICENSE
         | 
| 88 | 
            +
            - README.md
         | 
| 89 | 
            +
            - Rakefile
         | 
| 26 90 | 
             
            - lib/plain_record.rb
         | 
| 27 | 
            -
            - lib/plain_record
         | 
| 28 | 
            -
            - lib/plain_record/ | 
| 91 | 
            +
            - lib/plain_record/association_proxy.rb
         | 
| 92 | 
            +
            - lib/plain_record/associations.rb
         | 
| 93 | 
            +
            - lib/plain_record/callbacks.rb
         | 
| 94 | 
            +
            - lib/plain_record/filepath.rb
         | 
| 95 | 
            +
            - lib/plain_record/model.rb
         | 
| 29 96 | 
             
            - lib/plain_record/model/entry.rb
         | 
| 30 97 | 
             
            - lib/plain_record/model/list.rb
         | 
| 31 98 | 
             
            - lib/plain_record/resource.rb
         | 
| 32 99 | 
             
            - lib/plain_record/version.rb
         | 
| 33 | 
            -
            -  | 
| 34 | 
            -
            - spec/ | 
| 35 | 
            -
            - spec/ | 
| 36 | 
            -
            - spec/data/ | 
| 37 | 
            -
            - spec/data/ | 
| 38 | 
            -
            - spec/data/ | 
| 100 | 
            +
            - plain_record.gemspec
         | 
| 101 | 
            +
            - spec/associations_spec.rb
         | 
| 102 | 
            +
            - spec/callbacks_spec.rb
         | 
| 103 | 
            +
            - spec/data/1/comments.yml
         | 
| 104 | 
            +
            - spec/data/1/post.md
         | 
| 105 | 
            +
            - spec/data/2/post.md
         | 
| 106 | 
            +
            - spec/data/3/post.md
         | 
| 39 107 | 
             
            - spec/data/authors/extern.yml
         | 
| 40 108 | 
             
            - spec/data/authors/intern.yml
         | 
| 41 | 
            -
            - spec/data/ | 
| 42 | 
            -
            - spec/ | 
| 43 | 
            -
            - spec/data/1
         | 
| 44 | 
            -
            - spec/data/1/post.m
         | 
| 45 | 
            -
            - spec/resource_spec.rb
         | 
| 109 | 
            +
            - spec/data/best/4/post.md
         | 
| 110 | 
            +
            - spec/filepath_spec.rb
         | 
| 46 111 | 
             
            - spec/model_spec.rb
         | 
| 47 | 
            -
            -  | 
| 48 | 
            -
            -  | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
            homepage: http://github.com/ai/plain_record
         | 
| 112 | 
            +
            - spec/resource_spec.rb
         | 
| 113 | 
            +
            - spec/spec_helper.rb
         | 
| 114 | 
            +
            homepage: https://github.com/ai/plain_record
         | 
| 115 | 
            +
            licenses: []
         | 
| 52 116 | 
             
            post_install_message: 
         | 
| 53 | 
            -
            rdoc_options: 
         | 
| 54 | 
            -
             | 
| 55 | 
            -
            - --main README.rdoc
         | 
| 56 | 
            -
            - --charset=utf-8
         | 
| 57 | 
            -
            - --all
         | 
| 58 | 
            -
            - --inline-source
         | 
| 59 | 
            -
            require_paths: 
         | 
| 117 | 
            +
            rdoc_options: []
         | 
| 118 | 
            +
            require_paths:
         | 
| 60 119 | 
             
            - lib
         | 
| 61 | 
            -
            required_ruby_version: !ruby/object:Gem::Requirement | 
| 62 | 
            -
               | 
| 63 | 
            -
               | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
               | 
| 120 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
              none: false
         | 
| 122 | 
            +
              requirements:
         | 
| 123 | 
            +
              - - ! '>='
         | 
| 124 | 
            +
                - !ruby/object:Gem::Version
         | 
| 125 | 
            +
                  version: '0'
         | 
| 126 | 
            +
                  segments:
         | 
| 127 | 
            +
                  - 0
         | 
| 128 | 
            +
                  hash: -111920136576463880
         | 
| 129 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 130 | 
            +
              none: false
         | 
| 131 | 
            +
              requirements:
         | 
| 132 | 
            +
              - - ! '>='
         | 
| 133 | 
            +
                - !ruby/object:Gem::Version
         | 
| 134 | 
            +
                  version: '0'
         | 
| 135 | 
            +
                  segments:
         | 
| 136 | 
            +
                  - 0
         | 
| 137 | 
            +
                  hash: -111920136576463880
         | 
| 73 138 | 
             
            requirements: []
         | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
            rubygems_version: 1.3.1
         | 
| 139 | 
            +
            rubyforge_project: 
         | 
| 140 | 
            +
            rubygems_version: 1.8.11
         | 
| 77 141 | 
             
            signing_key: 
         | 
| 78 | 
            -
            specification_version:  | 
| 142 | 
            +
            specification_version: 3
         | 
| 79 143 | 
             
            summary: Data persistence, which use human editable and readable plain text files.
         | 
| 80 | 
            -
            test_files: 
         | 
| 81 | 
            -
             | 
| 82 | 
            -
            - spec/data
         | 
| 83 | 
            -
            - spec/data/2
         | 
| 84 | 
            -
            - spec/data/2/post.m
         | 
| 85 | 
            -
            - spec/data/authors
         | 
| 86 | 
            -
            - spec/data/authors/extern.yml
         | 
| 87 | 
            -
            - spec/data/authors/intern.yml
         | 
| 88 | 
            -
            - spec/data/3
         | 
| 89 | 
            -
            - spec/data/3/post.m
         | 
| 90 | 
            -
            - spec/data/1
         | 
| 91 | 
            -
            - spec/data/1/post.m
         | 
| 92 | 
            -
            - spec/resource_spec.rb
         | 
| 93 | 
            -
            - spec/model_spec.rb
         | 
| 144 | 
            +
            test_files: []
         | 
| 145 | 
            +
            has_rdoc: 
         | 
    
        data/README.rdoc
    DELETED
    
    | @@ -1,96 +0,0 @@ | |
| 1 | 
            -
            = Plain Record
         | 
| 2 | 
            -
            Plaint Record is a data persistence, which use human editable and readable plain
         | 
| 3 | 
            -
            text files. It’s ideal for static generated sites, like blog or homepage.
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            If you want to write another static website generator, you didn’t need to write
         | 
| 6 | 
            -
            another file parser – you can use Plain Record.
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            == How To
         | 
| 9 | 
            -
            For example we will create simple blog storage with posts and comments.
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            1. Add Plain Record to your application:
         | 
| 12 | 
            -
               
         | 
| 13 | 
            -
                 require 'plain_record'
         | 
| 14 | 
            -
               
         | 
| 15 | 
            -
            2. Set storage root – dir, which will contain all data files:
         | 
| 16 | 
            -
              
         | 
| 17 | 
            -
                 PlainRecord.root = 'data/'
         | 
| 18 | 
            -
               
         | 
| 19 | 
            -
            3. Create Post class, include <tt>Plain::Resource</tt> module, set glob pattern
         | 
| 20 | 
            -
               to posts files and define properties:
         | 
| 21 | 
            -
               
         | 
| 22 | 
            -
                 class Post
         | 
| 23 | 
            -
                   include Plain::Resource
         | 
| 24 | 
            -
                   
         | 
| 25 | 
            -
                   entry_in '*/post.m'
         | 
| 26 | 
            -
                   
         | 
| 27 | 
            -
                   property :title
         | 
| 28 | 
            -
                   property :tags
         | 
| 29 | 
            -
                   text :summary
         | 
| 30 | 
            -
                   text :content
         | 
| 31 | 
            -
                 end
         | 
| 32 | 
            -
               
         | 
| 33 | 
            -
            4. Create new post file <tt>data/first/post.m</tt>. Properties will be saved as
         | 
| 34 | 
            -
               YAML and text will be placed as plain text, which is separated by 3 dashes:
         | 
| 35 | 
            -
               
         | 
| 36 | 
            -
                 title: My first post
         | 
| 37 | 
            -
                 tags: test, first
         | 
| 38 | 
            -
                 ---
         | 
| 39 | 
            -
                 It is short post summary.
         | 
| 40 | 
            -
                 ---
         | 
| 41 | 
            -
                 And this is big big post text.
         | 
| 42 | 
            -
                 In several lines.
         | 
| 43 | 
            -
               
         | 
| 44 | 
            -
            5. Also you can use files with list of entries. For example, comments:
         | 
| 45 | 
            -
               
         | 
| 46 | 
            -
                 class Comment
         | 
| 47 | 
            -
                   include Plain::Resource
         | 
| 48 | 
            -
                   
         | 
| 49 | 
            -
                   list_in '*/comments.yml'
         | 
| 50 | 
            -
                   
         | 
| 51 | 
            -
                   property :name
         | 
| 52 | 
            -
                   property :comment
         | 
| 53 | 
            -
                 end
         | 
| 54 | 
            -
               
         | 
| 55 | 
            -
               You can’t use text fields in list files.
         | 
| 56 | 
            -
            6. List files is a just YAML array. For example,
         | 
| 57 | 
            -
               <tt>data/first/comments.yml</tt>:
         | 
| 58 | 
            -
               
         | 
| 59 | 
            -
                 - author: Anonymous
         | 
| 60 | 
            -
                   comment: I like it!
         | 
| 61 | 
            -
                 - author: Friend
         | 
| 62 | 
            -
                   comment: You first post it shit.
         | 
| 63 | 
            -
               
         | 
| 64 | 
            -
            7. Get all post:
         | 
| 65 | 
            -
               
         | 
| 66 | 
            -
                 Post.all # will return array with our first post
         | 
| 67 | 
            -
               
         | 
| 68 | 
            -
            8. Get specify enrties:
         | 
| 69 | 
            -
               
         | 
| 70 | 
            -
                 Comment.all(author: 'Anonymous')
         | 
| 71 | 
            -
                 Post.all(title: /first/)
         | 
| 72 | 
            -
                 Post.all { |i| i.tags.length == 2 }
         | 
| 73 | 
            -
               
         | 
| 74 | 
            -
            9. To get one entry use +first+ method, which also can take matchers. You can
         | 
| 75 | 
            -
               access for properties and text by methods with same name:
         | 
| 76 | 
            -
               
         | 
| 77 | 
            -
                 post = Post.first(title: /first/)
         | 
| 78 | 
            -
                 post.title   #=> "My first post"
         | 
| 79 | 
            -
                 post.tags    #=> ["test", "first"]
         | 
| 80 | 
            -
                 post.summary #=> "It is short post summary."
         | 
| 81 | 
            -
               
         | 
| 82 | 
            -
            10. You can also change and save entries:
         | 
| 83 | 
            -
                
         | 
| 84 | 
            -
                  post.title = 'First post'
         | 
| 85 | 
            -
                  post.save
         | 
| 86 | 
            -
                
         | 
| 87 | 
            -
            11. And delete it (with empty dirs in it file path):
         | 
| 88 | 
            -
                
         | 
| 89 | 
            -
                  post.destroy
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            == License
         | 
| 92 | 
            -
            Plain Record is licensed under the GNU Lesser General Public License version 3. 
         | 
| 93 | 
            -
            You can read it in LICENSE file or in www.gnu.org/licenses/lgpl.html. 
         | 
| 94 | 
            -
             | 
| 95 | 
            -
            == Author
         | 
| 96 | 
            -
            Andrey “A.I.” Sitnik <andrey@sitnik.ru> 
         | 
    
        data/spec/data/3/post.m
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            title: Third
         |