document_mapper 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/document_mapper/version.rb +1 -1
- data/lib/document_mapper/yaml_parsing.rb +9 -1
- data/test/document_mapper/document_mapper_test.rb +20 -0
- metadata +36 -54
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1bc09066c1fbf38ca380a29e31d9d8c4f74ffb914e2b412d721bbbb5842709bf
|
4
|
+
data.tar.gz: 12de89688244203d412513377cb8ab1151bdbb2215a8674ac21be54958ee597d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c812a89c9c773906f3770e645db50deca4fd57730af0906df72e77fbe6b156465b0f8fbe43dd054608f0e9dfd54d0738e3bf6a789c366bec6c9bfa5f43f52e8e
|
7
|
+
data.tar.gz: 46718a0fe7a278b3f501eb9949d07c3133b16655356b9fed997444ef4c7f138e8089f4a767b88e36aeb980f66a5d130e12c6066670814d48d432af157635f640
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module DocumentMapper
|
2
|
+
class YamlParsingError < StandardError; end
|
3
|
+
|
2
4
|
module YamlParsing
|
3
5
|
def read_yaml
|
4
6
|
file_path = self.attributes[:file_path]
|
@@ -6,7 +8,7 @@ module DocumentMapper
|
|
6
8
|
|
7
9
|
if @content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
8
10
|
@content = @content[($1.size + $2.size)..-1]
|
9
|
-
self.attributes.update(
|
11
|
+
self.attributes.update(yaml_load($1, file_path).symbolize_keys)
|
10
12
|
end
|
11
13
|
|
12
14
|
file_name = File.basename(file_path)
|
@@ -35,5 +37,11 @@ module DocumentMapper
|
|
35
37
|
self.class.define_attribute_methods self.attributes.keys
|
36
38
|
self.attributes.keys.each { |attr| self.class.define_read_method attr }
|
37
39
|
end
|
40
|
+
|
41
|
+
def yaml_load(yaml, file)
|
42
|
+
YAML.load(yaml)
|
43
|
+
rescue ArgumentError, Psych::SyntaxError
|
44
|
+
raise YamlParsingError, "Unable to parse YAML of #{file}"
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
@@ -336,6 +336,26 @@ EOS
|
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
|
+
describe 'loading a document with invalid yaml' do
|
340
|
+
it 'should raise with a decent error message' do
|
341
|
+
@file_path = File.expand_path('test/documents/invalid_yaml.textile')
|
342
|
+
File.open(@file_path, 'w') do |f|
|
343
|
+
f.write <<-EOS
|
344
|
+
---
|
345
|
+
title: Look: Invalid YAML!
|
346
|
+
---
|
347
|
+
|
348
|
+
This is definitely gonna blow up.
|
349
|
+
EOS
|
350
|
+
end
|
351
|
+
proc { MyDocument.reload }.must_raise(DocumentMapper::YamlParsingError, "Unable to parse YAML of #{@file_path}")
|
352
|
+
end
|
353
|
+
|
354
|
+
def teardown
|
355
|
+
File.delete @file_path
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
339
359
|
describe 'multiple document classes' do
|
340
360
|
it 'can serve multiple document directories' do
|
341
361
|
MyDocument.directory = 'test/documents'
|
metadata
CHANGED
@@ -1,120 +1,104 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: document_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ralph von der Heyden
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-07-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activemodel
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0
|
47
|
+
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
54
|
+
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: tilt
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
68
|
+
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: RedCloth
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
75
|
+
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
82
|
+
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: minitest
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
89
|
+
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
110
|
-
description:
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
scripts.
|
116
|
-
|
117
|
-
'
|
96
|
+
version: '0'
|
97
|
+
description: " DocumentMapper is an object mapper for plain text documents. The documents
|
98
|
+
look like the ones used in jekyll (http://github.com/mojombo/jekyll). They consist
|
99
|
+
of a preambel written in YAML (also called YAML front matter), and some content
|
100
|
+
in the format you prefer, e.g. Textile. This enables you to write documents in your
|
101
|
+
favorite editor and access the content and metadata of these in your Ruby scripts.\n"
|
118
102
|
email: ralph@rvdh.de
|
119
103
|
executables: []
|
120
104
|
extensions: []
|
@@ -122,6 +106,7 @@ extra_rdoc_files: []
|
|
122
106
|
files:
|
123
107
|
- LICENSE
|
124
108
|
- README.md
|
109
|
+
- lib/document_mapper.rb
|
125
110
|
- lib/document_mapper/attribute_methods.rb
|
126
111
|
- lib/document_mapper/constants.rb
|
127
112
|
- lib/document_mapper/core_ext/object.rb
|
@@ -133,7 +118,6 @@ files:
|
|
133
118
|
- lib/document_mapper/to_html.rb
|
134
119
|
- lib/document_mapper/version.rb
|
135
120
|
- lib/document_mapper/yaml_parsing.rb
|
136
|
-
- lib/document_mapper.rb
|
137
121
|
- test/document_mapper/core_ext/symbol_test.rb
|
138
122
|
- test/document_mapper/document_mapper_test.rb
|
139
123
|
- test/document_mapper/selector_test.rb
|
@@ -145,25 +129,23 @@ files:
|
|
145
129
|
- test/test_base.rb
|
146
130
|
homepage: http://github.com/ralph/document_mapper
|
147
131
|
licenses: []
|
132
|
+
metadata: {}
|
148
133
|
post_install_message:
|
149
134
|
rdoc_options: []
|
150
135
|
require_paths:
|
151
136
|
- lib
|
152
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
138
|
requirements:
|
155
|
-
- -
|
139
|
+
- - ">="
|
156
140
|
- !ruby/object:Gem::Version
|
157
141
|
version: '0'
|
158
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
143
|
requirements:
|
161
|
-
- -
|
144
|
+
- - ">="
|
162
145
|
- !ruby/object:Gem::Version
|
163
146
|
version: '0'
|
164
147
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 1.8.23
|
148
|
+
rubygems_version: 3.1.6
|
167
149
|
signing_key:
|
168
150
|
specification_version: 3
|
169
151
|
summary: DocumentMapper is an object mapper for plain text documents.
|