document_mapper 0.1.7 → 0.2.1
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 +60 -54
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9ab11d53186b4024ab9e6d6dccbe9b87e79ac6bcc5eaca018ad6ac5aba88b06
|
4
|
+
data.tar.gz: c0431bd44df0df6e1d98f559155a457cde183332c7dd931ad49d071aa0479611
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f0d93678a4030ed955b38d7b529821a5c04dc7e13cb4d9f0b948387f01be750e744a9521e5710e326cff5fa7a6a7c23f7bd680fe4ca4e76e5318f8193d0af91
|
7
|
+
data.tar.gz: a2801844b698e9510e4734eef79df903e23dcd6449d34477bef0ba4bbd0d0eda22fe88d4952f07d7c4182642f807cf9462929d35e4174587678313580b0c57d5
|
@@ -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).transform_keys(&:to_sym))
|
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,90 +1,104 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: document_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
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
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: activemodel
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
+
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0
|
47
|
+
version: '0'
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: tilt
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
61
|
+
version: '0'
|
55
62
|
type: :runtime
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: RedCloth
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
|
-
- -
|
73
|
+
- - ">="
|
64
74
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
75
|
+
version: '0'
|
66
76
|
type: :development
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest
|
71
|
-
requirement:
|
72
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - ">="
|
75
88
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
89
|
+
version: '0'
|
77
90
|
type: :development
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
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"
|
88
102
|
email: ralph@rvdh.de
|
89
103
|
executables: []
|
90
104
|
extensions: []
|
@@ -92,6 +106,7 @@ extra_rdoc_files: []
|
|
92
106
|
files:
|
93
107
|
- LICENSE
|
94
108
|
- README.md
|
109
|
+
- lib/document_mapper.rb
|
95
110
|
- lib/document_mapper/attribute_methods.rb
|
96
111
|
- lib/document_mapper/constants.rb
|
97
112
|
- lib/document_mapper/core_ext/object.rb
|
@@ -103,7 +118,6 @@ files:
|
|
103
118
|
- lib/document_mapper/to_html.rb
|
104
119
|
- lib/document_mapper/version.rb
|
105
120
|
- lib/document_mapper/yaml_parsing.rb
|
106
|
-
- lib/document_mapper.rb
|
107
121
|
- test/document_mapper/core_ext/symbol_test.rb
|
108
122
|
- test/document_mapper/document_mapper_test.rb
|
109
123
|
- test/document_mapper/selector_test.rb
|
@@ -115,31 +129,23 @@ files:
|
|
115
129
|
- test/test_base.rb
|
116
130
|
homepage: http://github.com/ralph/document_mapper
|
117
131
|
licenses: []
|
132
|
+
metadata: {}
|
118
133
|
post_install_message:
|
119
134
|
rdoc_options: []
|
120
135
|
require_paths:
|
121
136
|
- lib
|
122
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
138
|
requirements:
|
125
|
-
- -
|
139
|
+
- - ">="
|
126
140
|
- !ruby/object:Gem::Version
|
127
141
|
version: '0'
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
hash: 2393159709703028438
|
131
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
143
|
requirements:
|
134
|
-
- -
|
144
|
+
- - ">="
|
135
145
|
- !ruby/object:Gem::Version
|
136
146
|
version: '0'
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
hash: 2393159709703028438
|
140
147
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 1.8.10
|
148
|
+
rubygems_version: 3.1.6
|
143
149
|
signing_key:
|
144
150
|
specification_version: 3
|
145
151
|
summary: DocumentMapper is an object mapper for plain text documents.
|