plain_record 0.2 → 0.3
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/.travis.yml +0 -1
- data/ChangeLog +11 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +10 -1
- data/README.md +18 -13
- data/lib/plain_record/association_proxy.rb +14 -13
- data/lib/plain_record/associations.rb +80 -80
- data/lib/plain_record/callbacks.rb +3 -2
- data/lib/plain_record/default.rb +56 -0
- data/lib/plain_record/extra/git.rb +97 -0
- data/lib/plain_record/extra/i18n.rb +157 -0
- data/lib/plain_record/filepath.rb +31 -39
- data/lib/plain_record/model/entry.rb +2 -1
- data/lib/plain_record/model/list.rb +2 -1
- data/lib/plain_record/model.rb +117 -88
- data/lib/plain_record/resource.rb +10 -9
- data/lib/plain_record/type.rb +86 -0
- data/lib/plain_record/version.rb +1 -1
- data/lib/plain_record.rb +17 -2
- data/plain_record.gemspec +3 -1
- data/spec/associations_spec.rb +12 -8
- data/spec/data/2/comments.yml +2 -0
- data/spec/data/2/post.md +1 -1
- data/spec/default_spec.rb +17 -0
- data/spec/filepath_spec.rb +10 -10
- data/spec/git_spec.rb +55 -0
- data/spec/i18n_spec.rb +167 -0
- data/spec/model_spec.rb +71 -30
- data/spec/plain_record_spec.rb +28 -0
- data/spec/resource_spec.rb +3 -3
- data/spec/spec_helper.rb +10 -24
- data/spec/type_spec.rb +129 -0
- metadata +47 -15
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe PlainRecord do
|
4
|
+
|
5
|
+
original_root = PlainRecord.root
|
6
|
+
after { PlainRecord.root = original_root }
|
7
|
+
|
8
|
+
it "should save root" do
|
9
|
+
PlainRecord.root = 'a/'
|
10
|
+
PlainRecord.root.should == 'a/'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should add last slash to root" do
|
14
|
+
PlainRecord.root = 'a'
|
15
|
+
PlainRecord.root.should == 'a/'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set pathname to root" do
|
19
|
+
PlainRecord.root = Pathname('a')
|
20
|
+
PlainRecord.root.should == 'a/'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should join path to root" do
|
24
|
+
PlainRecord.root = 'a'
|
25
|
+
PlainRecord.root('b').should == 'a/b'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/resource_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,9 @@ class Post
|
|
5
5
|
|
6
6
|
entry_in 'data/*/post.md'
|
7
7
|
|
8
|
-
|
9
|
-
text
|
10
|
-
text
|
8
|
+
field :title
|
9
|
+
text :summary
|
10
|
+
text :content
|
11
11
|
end
|
12
12
|
|
13
13
|
class FilepathPost
|
@@ -18,7 +18,7 @@ class FilepathPost
|
|
18
18
|
virtual :category, in_filepath(1)
|
19
19
|
virtual :name, in_filepath(2)
|
20
20
|
|
21
|
-
|
21
|
+
field :title
|
22
22
|
end
|
23
23
|
|
24
24
|
class Author
|
@@ -26,9 +26,9 @@ class Author
|
|
26
26
|
|
27
27
|
list_in 'data/authors/*.yml'
|
28
28
|
|
29
|
-
virtual
|
30
|
-
|
31
|
-
|
29
|
+
virtual :type, in_filepath(1)
|
30
|
+
field :login
|
31
|
+
field :name
|
32
32
|
end
|
33
33
|
|
34
34
|
PlainRecord.root = File.dirname(__FILE__)
|
@@ -44,8 +44,9 @@ INTERN = File.join(File.dirname(__FILE__), 'data/authors/intern.yml')
|
|
44
44
|
EXTERN = File.join(File.dirname(__FILE__), 'data/authors/extern.yml')
|
45
45
|
|
46
46
|
def model_methods(model)
|
47
|
-
|
48
|
-
|
47
|
+
(model.instance_methods -
|
48
|
+
Object.instance_methods -
|
49
|
+
PlainRecord::Resource.instance_methods).map { |i| i.to_s }
|
49
50
|
end
|
50
51
|
|
51
52
|
RSpec::Matchers.define :has_methods do |*methods|
|
@@ -60,18 +61,3 @@ RSpec::Matchers.define :has_yaml do |data|
|
|
60
61
|
YAML.load(file.read).should == data
|
61
62
|
end
|
62
63
|
end
|
63
|
-
|
64
|
-
class Definers
|
65
|
-
def self.accessor
|
66
|
-
proc { :accessor }
|
67
|
-
end
|
68
|
-
def self.writer
|
69
|
-
proc { :writer }
|
70
|
-
end
|
71
|
-
def self.reader
|
72
|
-
proc { :reader }
|
73
|
-
end
|
74
|
-
def self.none
|
75
|
-
proc { nil }
|
76
|
-
end
|
77
|
-
end
|
data/spec/type_spec.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe PlainRecord::Type do
|
4
|
+
|
5
|
+
originParsers = PlainRecord::Type.parsers
|
6
|
+
originStringifies = PlainRecord::Type.stringifies
|
7
|
+
after do
|
8
|
+
PlainRecord::Type.parsers = originParsers
|
9
|
+
PlainRecord::Type.stringifies = originStringifies
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set field type to string" do
|
13
|
+
klass = Class.new do
|
14
|
+
include PlainRecord::Resource
|
15
|
+
field :one, type(String)
|
16
|
+
end
|
17
|
+
|
18
|
+
a = klass.new
|
19
|
+
a.one.should be_nil
|
20
|
+
|
21
|
+
a.data['one'] = 1
|
22
|
+
a.one.should == '1'
|
23
|
+
|
24
|
+
a.one = 2
|
25
|
+
a.data['one'].should == '2'
|
26
|
+
|
27
|
+
a.one = nil
|
28
|
+
a.data['one'].should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set field type to integer" do
|
32
|
+
klass = Class.new do
|
33
|
+
include PlainRecord::Resource
|
34
|
+
field :one, type(Integer)
|
35
|
+
end
|
36
|
+
|
37
|
+
a = klass.new
|
38
|
+
a.one.should be_nil
|
39
|
+
|
40
|
+
a.data['one'] = '1'
|
41
|
+
a.one.should == 1
|
42
|
+
|
43
|
+
a.one = '2'
|
44
|
+
a.data['one'].should == 2
|
45
|
+
|
46
|
+
a.one = nil
|
47
|
+
a.data['one'].should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set field type to float" do
|
51
|
+
klass = Class.new do
|
52
|
+
include PlainRecord::Resource
|
53
|
+
field :one, type(Float)
|
54
|
+
end
|
55
|
+
|
56
|
+
a = klass.new
|
57
|
+
a.one.should be_nil
|
58
|
+
|
59
|
+
a.data['one'] = '1.5'
|
60
|
+
a.one.should == 1.5
|
61
|
+
|
62
|
+
a.one = '2.5'
|
63
|
+
a.data['one'].should == 2.5
|
64
|
+
|
65
|
+
a.one = nil
|
66
|
+
a.data['one'].should be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set field type to time" do
|
70
|
+
klass = Class.new do
|
71
|
+
include PlainRecord::Resource
|
72
|
+
field :one, type(Time)
|
73
|
+
end
|
74
|
+
|
75
|
+
a = klass.new
|
76
|
+
a.one.should be_nil
|
77
|
+
|
78
|
+
a.data['one'] = '1970-01-01 00:00:00 UTC'
|
79
|
+
a.one.should == Time.at(0).utc
|
80
|
+
|
81
|
+
a.data['one'] = Time.at(0).utc
|
82
|
+
a.one.should == Time.at(0).utc
|
83
|
+
|
84
|
+
a.one = Time.at(1).utc
|
85
|
+
a.data['one'].should =~ /1970-01-01 00:00:01 (UTC|GMT)/
|
86
|
+
|
87
|
+
a.one = nil
|
88
|
+
a.data['one'].should be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should set field type to date" do
|
92
|
+
klass = Class.new do
|
93
|
+
include PlainRecord::Resource
|
94
|
+
field :one, type(Date)
|
95
|
+
end
|
96
|
+
|
97
|
+
a = klass.new
|
98
|
+
a.one.should be_nil
|
99
|
+
|
100
|
+
a.data['one'] = '1970-01-01'
|
101
|
+
a.one.should == Date.parse('1970-01-01')
|
102
|
+
|
103
|
+
a.data['one'] = Date.parse('1970-01-01')
|
104
|
+
a.one.should == Date.parse('1970-01-01')
|
105
|
+
|
106
|
+
a.one = Date.parse('1970-01-02')
|
107
|
+
a.data['one'].should == Date.parse('1970-01-02')
|
108
|
+
|
109
|
+
a.one = nil
|
110
|
+
a.data['one'].should be_nil
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should allow to set custom type" do
|
114
|
+
type = Class.new
|
115
|
+
PlainRecord::Type.parsers = { type => '1' }
|
116
|
+
PlainRecord::Type.stringifies = { type => '2' }
|
117
|
+
|
118
|
+
klass = Class.new do
|
119
|
+
include PlainRecord::Resource
|
120
|
+
field :one, type(type)
|
121
|
+
end
|
122
|
+
|
123
|
+
a = klass.new
|
124
|
+
a.one.should == 1
|
125
|
+
a.one = 5
|
126
|
+
a.data['one'].should == 2
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &23439240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.10
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *23439240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yard
|
27
|
-
requirement: &
|
27
|
+
requirement: &23438660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *23438660
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &23438060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23438060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &23437480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *23437480
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: redcarpet
|
60
|
-
requirement: &
|
60
|
+
requirement: &23436940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,9 +65,31 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *23436940
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: r18n-core
|
71
|
+
requirement: &23436360 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *23436360
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: i18n
|
82
|
+
requirement: &23435760 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *23435760
|
69
91
|
description: ! " Plain Record is a data persistence, which use human editable and\n
|
70
|
-
\ readable plain text files. It
|
92
|
+
\ readable plain text files. It's ideal for static generated sites,\n like
|
71
93
|
blog or homepage.\n"
|
72
94
|
email: andrey@sitnik.ru
|
73
95
|
executables: []
|
@@ -91,26 +113,36 @@ files:
|
|
91
113
|
- lib/plain_record/association_proxy.rb
|
92
114
|
- lib/plain_record/associations.rb
|
93
115
|
- lib/plain_record/callbacks.rb
|
116
|
+
- lib/plain_record/default.rb
|
117
|
+
- lib/plain_record/extra/git.rb
|
118
|
+
- lib/plain_record/extra/i18n.rb
|
94
119
|
- lib/plain_record/filepath.rb
|
95
120
|
- lib/plain_record/model.rb
|
96
121
|
- lib/plain_record/model/entry.rb
|
97
122
|
- lib/plain_record/model/list.rb
|
98
123
|
- lib/plain_record/resource.rb
|
124
|
+
- lib/plain_record/type.rb
|
99
125
|
- lib/plain_record/version.rb
|
100
126
|
- plain_record.gemspec
|
101
127
|
- spec/associations_spec.rb
|
102
128
|
- spec/callbacks_spec.rb
|
103
129
|
- spec/data/1/comments.yml
|
104
130
|
- spec/data/1/post.md
|
131
|
+
- spec/data/2/comments.yml
|
105
132
|
- spec/data/2/post.md
|
106
133
|
- spec/data/3/post.md
|
107
134
|
- spec/data/authors/extern.yml
|
108
135
|
- spec/data/authors/intern.yml
|
109
136
|
- spec/data/best/4/post.md
|
137
|
+
- spec/default_spec.rb
|
110
138
|
- spec/filepath_spec.rb
|
139
|
+
- spec/git_spec.rb
|
140
|
+
- spec/i18n_spec.rb
|
111
141
|
- spec/model_spec.rb
|
142
|
+
- spec/plain_record_spec.rb
|
112
143
|
- spec/resource_spec.rb
|
113
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/type_spec.rb
|
114
146
|
homepage: https://github.com/ai/plain_record
|
115
147
|
licenses: []
|
116
148
|
post_install_message:
|
@@ -125,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
157
|
version: '0'
|
126
158
|
segments:
|
127
159
|
- 0
|
128
|
-
hash: -
|
160
|
+
hash: -2998465728385447997
|
129
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
162
|
none: false
|
131
163
|
requirements:
|
@@ -134,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
166
|
version: '0'
|
135
167
|
segments:
|
136
168
|
- 0
|
137
|
-
hash: -
|
169
|
+
hash: -2998465728385447997
|
138
170
|
requirements: []
|
139
171
|
rubyforge_project:
|
140
172
|
rubygems_version: 1.8.11
|