plain_record 0.1.0 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +29 -41
- data/lib/plain_record.rb +22 -2
- 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.rb +134 -61
- data/lib/plain_record/model/entry.rb +20 -8
- data/lib/plain_record/model/list.rb +30 -8
- data/lib/plain_record/resource.rb +76 -18
- data/lib/plain_record/version.rb +3 -0
- 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 +100 -39
- data/spec/resource_spec.rb +84 -23
- data/spec/spec_helper.rb +33 -14
- metadata +119 -61
- data/README.rdoc +0 -92
- data/VERSION +0 -1
- data/spec/data/3/post.m +0 -1
data/spec/spec_helper.rb
CHANGED
@@ -2,43 +2,62 @@ require File.join(File.dirname(__FILE__), '../lib/plain_record')
|
|
2
2
|
|
3
3
|
class Post
|
4
4
|
include PlainRecord::Resource
|
5
|
-
|
6
|
-
entry_in 'data/*/post.
|
7
|
-
|
5
|
+
|
6
|
+
entry_in 'data/*/post.md'
|
7
|
+
|
8
8
|
property :title
|
9
9
|
text :summary
|
10
10
|
text :content
|
11
11
|
end
|
12
12
|
|
13
|
+
class FilepathPost
|
14
|
+
include PlainRecord::Resource
|
15
|
+
|
16
|
+
entry_in 'data/**/*/post.md'
|
17
|
+
|
18
|
+
virtual :category, in_filepath(1)
|
19
|
+
virtual :name, in_filepath(2)
|
20
|
+
|
21
|
+
property :title
|
22
|
+
end
|
23
|
+
|
13
24
|
class Author
|
14
25
|
include PlainRecord::Resource
|
15
|
-
|
26
|
+
|
16
27
|
list_in 'data/authors/*.yml'
|
17
|
-
|
28
|
+
|
29
|
+
virtual :type, in_filepath(1)
|
18
30
|
property :login
|
19
31
|
property :name
|
20
32
|
end
|
21
33
|
|
22
34
|
PlainRecord.root = File.dirname(__FILE__)
|
23
35
|
|
24
|
-
FIRST = File.join(File.dirname(__FILE__), 'data/1/post.
|
25
|
-
SECOND = File.join(File.dirname(__FILE__), 'data/2/post.
|
26
|
-
THIRD = File.join(File.dirname(__FILE__), 'data/3/post.
|
27
|
-
FIRST_POST
|
36
|
+
FIRST = File.join(File.dirname(__FILE__), 'data/1/post.md')
|
37
|
+
SECOND = File.join(File.dirname(__FILE__), 'data/2/post.md')
|
38
|
+
THIRD = File.join(File.dirname(__FILE__), 'data/3/post.md')
|
39
|
+
FIRST_POST = Post.load_file(FIRST)
|
28
40
|
SECOND_POST = Post.load_file(SECOND)
|
29
|
-
THIRD_POST
|
41
|
+
THIRD_POST = Post.load_file(THIRD)
|
30
42
|
|
31
43
|
INTERN = File.join(File.dirname(__FILE__), 'data/authors/intern.yml')
|
32
44
|
EXTERN = File.join(File.dirname(__FILE__), 'data/authors/extern.yml')
|
33
45
|
|
34
46
|
def model_methods(model)
|
35
|
-
model.instance_methods - Object.instance_methods -
|
36
|
-
PlainRecord::Resource.instance_methods
|
47
|
+
(model.instance_methods - Object.instance_methods -
|
48
|
+
PlainRecord::Resource.instance_methods).map { |i| i.to_s }
|
37
49
|
end
|
38
50
|
|
39
|
-
|
51
|
+
RSpec::Matchers.define :has_methods do |*methods|
|
40
52
|
match do |model|
|
41
|
-
model_methods(model).sort == methods.sort
|
53
|
+
model_methods(model).sort == methods.map! { |i| i.to_s }.sort
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
RSpec::Matchers.define :has_yaml do |data|
|
58
|
+
match do |file|
|
59
|
+
file.rewind
|
60
|
+
YAML.load(file.read).should == data
|
42
61
|
end
|
43
62
|
end
|
44
63
|
|
metadata
CHANGED
@@ -1,87 +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: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
- Andrey Sitnik
|
7
|
+
authors:
|
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
|
-
|
75
|
+
extra_rdoc_files:
|
76
|
+
- README.md
|
23
77
|
- LICENSE
|
24
|
-
-
|
25
|
-
files:
|
78
|
+
- ChangeLog
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- .rspec
|
82
|
+
- .travis.yml
|
83
|
+
- .yardopts
|
84
|
+
- ChangeLog
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
26
87
|
- LICENSE
|
27
|
-
- README.
|
88
|
+
- README.md
|
28
89
|
- Rakefile
|
29
|
-
- VERSION
|
30
90
|
- lib/plain_record.rb
|
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
|
31
95
|
- lib/plain_record/model.rb
|
32
96
|
- lib/plain_record/model/entry.rb
|
33
97
|
- lib/plain_record/model/list.rb
|
34
98
|
- lib/plain_record/resource.rb
|
35
|
-
-
|
36
|
-
-
|
37
|
-
- spec/
|
99
|
+
- lib/plain_record/version.rb
|
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
|
38
107
|
- spec/data/authors/extern.yml
|
39
108
|
- spec/data/authors/intern.yml
|
109
|
+
- spec/data/best/4/post.md
|
110
|
+
- spec/filepath_spec.rb
|
40
111
|
- spec/model_spec.rb
|
41
112
|
- spec/resource_spec.rb
|
42
113
|
- spec/spec_helper.rb
|
43
|
-
|
44
|
-
|
114
|
+
homepage: https://github.com/ai/plain_record
|
115
|
+
licenses: []
|
45
116
|
post_install_message:
|
46
|
-
rdoc_options:
|
47
|
-
|
48
|
-
- --title "Plain Record"
|
49
|
-
- --main README.rdoc
|
50
|
-
- --charset=utf-8
|
51
|
-
- --all
|
52
|
-
- --inline-source
|
53
|
-
require_paths:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
54
119
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
67
138
|
requirements: []
|
68
|
-
|
69
|
-
|
70
|
-
rubygems_version: 1.3.1
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.11
|
71
141
|
signing_key:
|
72
|
-
specification_version:
|
142
|
+
specification_version: 3
|
73
143
|
summary: Data persistence, which use human editable and readable plain text files.
|
74
|
-
test_files:
|
75
|
-
|
76
|
-
- spec/data
|
77
|
-
- spec/data/2
|
78
|
-
- spec/data/2/post.m
|
79
|
-
- spec/data/authors
|
80
|
-
- spec/data/authors/extern.yml
|
81
|
-
- spec/data/authors/intern.yml
|
82
|
-
- spec/data/3
|
83
|
-
- spec/data/3/post.m
|
84
|
-
- spec/data/1
|
85
|
-
- spec/data/1/post.m
|
86
|
-
- spec/resource_spec.rb
|
87
|
-
- spec/model_spec.rb
|
144
|
+
test_files: []
|
145
|
+
has_rdoc:
|
data/README.rdoc
DELETED
@@ -1,92 +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
|
-
== License
|
88
|
-
Plain Record is licensed under the GNU Lesser General Public License version 3.
|
89
|
-
You can read it in LICENSE file or in www.gnu.org/licenses/lgpl.html.
|
90
|
-
|
91
|
-
== Author
|
92
|
-
Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|
data/spec/data/3/post.m
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
title: Third
|