# plain_record
**Repository Path**: mirrors_ai/plain_record
## Basic Information
- **Project Name**: plain_record
- **Description**: Data persistence with human readable and editable storage.
- **Primary Language**: Unknown
- **License**: LGPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-01-26
- **Last Updated**: 2025-09-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Plain Record [](https://travis-ci.org/ai/plain_record)
Plaint Record is a data persistence, which use human editable and readable plain
text files. It’s ideal for static generated sites, like blog or homepage.
If you want to write another static website generator, you don’t need to write
another file parser – you can use Plain Record.
## How To
For example we will create simple blog storage with posts and comments.
1. Add Plain Record to your application Gemfile:
```ruby
gem "plain_record"
```
2. Set storage root – dir, which will contain all data files:
```ruby
PlainRecord.root = 'data/'
```
3. Create Post class, include `Plain::Resource` module, set glob pattern
to posts files and define fields:
```ruby
class Post
include Plain::Resource
entry_in '*/post.md'
virtual :name, in_filepath(1)
virtual :comments, many(Comment)
field :title default("Untitled")
field :tags default([])
field :created type(Time)
text :summary
text :content
end
```
4. Create new post file `data/first/post.md`. Fields will be saved as
YAML and text will be placed as plain text, which is separated by 3 dashes:
```
title: My first post
tags: test, first
---
It is short post summary.
---
And this is big big post text.
In several lines.
```
5. Also you can use files with list of entries. For example, comments:
```ruby
class Comment
include Plain::Resource
list_in '*/comments.yml'
virtual :post_name, in_filepath(1)
virtual :post, one(Post)
field :author
field :comment
end
```
You can’t use text fields in list files.
6. List files is a just YAML array. For example, `data/first/comments.yml`:
\- author: Anonymous
comment: I like it!
\- author: Friend
comment: You first post it shit.
7. Get all post:
```ruby
Post.all # will return array with our first post
```
8. Get specific entries:
```ruby
Comment.all(author: 'Anonymous')
Post.all(title: /first/)
Post.all { |i| i.tags.length == 2 }
```
9. To get one entry use `first` method, which also can take matchers. You can
access for fields and text by methods with same name:
```ruby
post = Post.first(title: /first/)
post.file #=> "data/first/post.md"
post.name #=> "first"
post.title #=> "My first post"
post.tags #=> ["test", "first"]
post.summary #=> "It is short post summary."
```
10. You can also change and save entries:
```ruby
post.title = 'First post'
post.save
```
11. And delete it (with empty dirs in it file path):
```ruby
post.destroy
```
## License
Plain Record is licensed under the GNU Lesser General Public License version 3.
See the LICENSE file or http://www.gnu.org/licenses/lgpl.html.
## Author
Andrey “A.I.” Sitnik