document_mapper 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,5 +1,7 @@
1
1
  h1. Document Mapper
2
2
 
3
+ !http://travis-ci.org/ralph/document_mapper.png!:http://travis-ci.org/ralph/document_mapper
4
+
3
5
  Document mapper is an object mapper for plain text documents. The documents look like the ones used in "jekyll":http://github.com/mojombo/jekyll, "toto":http://github.com/cloudhead/toto or "Serious":http://github.com/colszowka/serious. They consist of a preambel written in YAML (also called YAML front matter), and some content in the format you prefer, e.g. Textile. This enables you to write documents in your favorite editor and access the content and metadata in your Ruby scripts.
4
6
 
5
7
 
@@ -46,7 +46,7 @@ module DocumentMapper
46
46
  self.reset
47
47
  @@directory = Dir.new File.expand_path(new_directory)
48
48
  @@directory.each do |file|
49
- next if ['.', '..'].include? file
49
+ next if file[0] == '.'
50
50
  self.from_file [@@directory.path, file].join('/')
51
51
  end
52
52
  end
@@ -102,6 +102,10 @@ module DocumentMapper
102
102
  def last
103
103
  @@documents.last
104
104
  end
105
+
106
+ def attributes
107
+ @@documents.map(&:attributes).map(&:keys).flatten.uniq.sort
108
+ end
105
109
  end
106
110
  end
107
111
  end
@@ -1,3 +1,3 @@
1
1
  module DocumentMapper
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.expand_path(__FILE__), '..', '..', '..', 'test_base')
1
+ require 'test_base'
2
2
  include DocumentMapper
3
3
 
4
4
  describe Symbol do
@@ -1,4 +1,4 @@
1
- require File.join(File.expand_path(__FILE__), '..', '..', 'test_base')
1
+ require 'test_base'
2
2
  include DocumentMapper
3
3
 
4
4
  describe MyDocument do
@@ -77,7 +77,12 @@ describe MyDocument do
77
77
  describe 'loading a documents directory' do
78
78
  it 'should load all the documents in that directory' do
79
79
  MyDocument.directory = 'test/documents'
80
- assert_equal [1,2,3,4], MyDocument.all.map(&:id)
80
+ assert_equal_set [1,2,3,4], MyDocument.all.map(&:id)
81
+ end
82
+
83
+ it 'should ignore all dotfile' do
84
+ MyDocument.directory = 'test/documents'
85
+ refute MyDocument.all.map(&:id).include?(5)
81
86
  end
82
87
  end
83
88
  end
@@ -106,15 +111,15 @@ describe MyDocument do
106
111
  end
107
112
 
108
113
  it 'should limit the documents to the number specified' do
109
- assert_equal [1,2], MyDocument.limit(2).all.map(&:id)
114
+ assert_equal_set [1,2], MyDocument.order_by(:id).limit(2).all.map(&:id)
110
115
  end
111
116
 
112
117
  it 'should offset the documents by the number specified' do
113
- assert_equal [3,4], MyDocument.offset(2).all.map(&:id)
118
+ assert_equal_set [3,4], MyDocument.order_by(:id).offset(2).all.map(&:id)
114
119
  end
115
120
 
116
121
  it 'should support offset and limit at the same time' do
117
- assert_equal [2,3], MyDocument.offset(1).limit(2).all.map(&:id)
122
+ assert_equal_set [2,3], MyDocument.order_by(:id).offset(1).limit(2).all.map(&:id)
118
123
  end
119
124
  end
120
125
 
@@ -164,13 +169,13 @@ describe MyDocument do
164
169
  it 'should work with dates' do
165
170
  found_documents = MyDocument.where(:year => 2010).all
166
171
  expected_documents = [sample_document_1, sample_document_2]
167
- assert_equal expected_documents.map(&:id), found_documents.map(&:id)
172
+ assert_equal_set expected_documents.map(&:id), found_documents.map(&:id)
168
173
  end
169
174
 
170
175
  it 'should not be confused by attributes not present in all documents' do
171
176
  MyDocument.directory = 'test/documents'
172
177
  result = MyDocument.where(:seldom_attribute => 'is seldom').all
173
- assert_equal [4], result.map(&:id)
178
+ assert_equal_set [4], result.map(&:id)
174
179
  end
175
180
  end
176
181
 
@@ -178,7 +183,7 @@ describe MyDocument do
178
183
  it 'should return the right documents' do
179
184
  selector = Selector.new :attribute => :id, :operator => 'gt'
180
185
  found_documents = MyDocument.where(selector => 2).all
181
- assert_equal [3,4], found_documents.map(&:id)
186
+ assert_equal_set [3,4], found_documents.map(&:id)
182
187
  end
183
188
  end
184
189
 
@@ -186,7 +191,7 @@ describe MyDocument do
186
191
  it 'should return the right documents' do
187
192
  selector = Selector.new :attribute => :id, :operator => 'gte'
188
193
  found_documents = MyDocument.where(selector => 2).all
189
- assert_equal [2,3,4], found_documents.map(&:id)
194
+ assert_equal_set [2,3,4], found_documents.map(&:id)
190
195
  end
191
196
  end
192
197
 
@@ -194,7 +199,7 @@ describe MyDocument do
194
199
  it 'should return the right documents' do
195
200
  selector = Selector.new :attribute => :id, :operator => 'in'
196
201
  found_documents = MyDocument.where(selector => [2,3]).all
197
- assert_equal [2,3], found_documents.map(&:id)
202
+ assert_equal_set [2,3], found_documents.map(&:id)
198
203
  end
199
204
  end
200
205
 
@@ -202,7 +207,7 @@ describe MyDocument do
202
207
  it 'should return the right documents' do
203
208
  selector = Selector.new :attribute => :id, :operator => 'lt'
204
209
  found_documents = MyDocument.where(selector => 2).all
205
- assert_equal [1], found_documents.map(&:id)
210
+ assert_equal_set [1], found_documents.map(&:id)
206
211
  end
207
212
  end
208
213
 
@@ -210,7 +215,7 @@ describe MyDocument do
210
215
  it 'should return the right documents' do
211
216
  selector = Selector.new :attribute => :id, :operator => 'lte'
212
217
  found_documents = MyDocument.where(selector => 2).all
213
- assert_equal [1,2], found_documents.map(&:id)
218
+ assert_equal_set [1,2], found_documents.map(&:id)
214
219
  end
215
220
  end
216
221
 
@@ -218,7 +223,7 @@ describe MyDocument do
218
223
  it 'include should return the right documents' do
219
224
  selector = Selector.new :attribute => :tags, :operator => 'include'
220
225
  found_documents = MyDocument.where(selector => 'ruby').all
221
- assert_equal [1,2], found_documents.map(&:id)
226
+ assert_equal_set [1,2], found_documents.map(&:id)
222
227
  end
223
228
  end
224
229
 
@@ -228,7 +233,7 @@ describe MyDocument do
228
233
  gt_selector = Selector.new :attribute => :id, :operator => 'gt'
229
234
  documents_proxy = MyDocument.where(in_selector => [2,3])
230
235
  found_documents = documents_proxy.where(gt_selector => 2).all
231
- assert_equal [3], found_documents.map(&:id)
236
+ assert_equal_set [3], found_documents.map(&:id)
232
237
  end
233
238
  end
234
239
 
@@ -236,7 +241,7 @@ describe MyDocument do
236
241
  it 'should return the right documents' do
237
242
  selector = Selector.new :attribute => :id, :operator => 'lte'
238
243
  found_documents = MyDocument.where(selector => 2, :status => :published).all
239
- assert_equal [1,2], found_documents.map(&:id)
244
+ assert_equal_set [1,2], found_documents.map(&:id)
240
245
  end
241
246
  end
242
247
  end
@@ -263,7 +268,7 @@ describe MyDocument do
263
268
 
264
269
  it 'should exclude documents that do not own the attribute' do
265
270
  found_documents = MyDocument.order_by(:status).all
266
- assert_equal [1,2], found_documents.map(&:id)
271
+ assert_equal [1,2].to_set, found_documents.map(&:id).to_set
267
272
  end
268
273
  end
269
274
 
@@ -289,6 +294,33 @@ EOS
289
294
  end
290
295
  end
291
296
 
297
+ describe 'getting a list of all the attributes' do
298
+ before do
299
+ MyDocument.directory = 'test/documents'
300
+ end
301
+
302
+ it 'should return an ordered list of all the attributes' do
303
+ expected_attributes = %w(
304
+ date
305
+ day
306
+ extension
307
+ file_name
308
+ file_name_without_extension
309
+ file_path
310
+ friends
311
+ id
312
+ month
313
+ seldom_attribute
314
+ special_attribute
315
+ status
316
+ tags
317
+ title
318
+ year
319
+ ).map(&:to_sym)
320
+ assert_equal expected_attributes, MyDocument.attributes
321
+ end
322
+ end
323
+
292
324
  def sample_file_path_1
293
325
  'test/documents/2010-08-08-test-document-file.textile'
294
326
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.expand_path(__FILE__), '..', '..', 'test_base')
1
+ require 'test_base'
2
2
  include DocumentMapper
3
3
 
4
4
  describe Selector do
data/test/test_base.rb CHANGED
@@ -1,11 +1,18 @@
1
+ require 'set'
1
2
  require 'minitest/spec'
2
3
  MiniTest::Unit.autorun
3
4
 
4
5
  lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
5
6
  $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir)
6
7
  require 'document_mapper'
7
- TEST_DIR = File.dirname(__FILE__)
8
8
 
9
9
  class MyDocument
10
10
  include DocumentMapper::Document
11
11
  end
12
+
13
+ module MiniTest::Assertions
14
+ def assert_equal_set exp, act, msg = nil
15
+ msg = message(msg) { "Expected #{mu_pp(exp)}, not #{mu_pp(act)}" }
16
+ assert(exp.to_set == act.to_set, msg)
17
+ end
18
+ end
metadata CHANGED
@@ -1,48 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: document_mapper
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
4
5
  prerelease:
5
- version: 0.1.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ralph von der Heyden
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-16 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-06-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activesupport
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2156885800 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
23
21
  version: 3.0.0
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: activemodel
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2156885800
25
+ - !ruby/object:Gem::Dependency
26
+ name: activemodel
27
+ requirement: &2156885300 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 3.0.0
35
33
  type: :runtime
36
- version_requirements: *id002
37
- description: " DocumentMapper is an object mapper for plain text documents. The documents look like the ones used in jekyll (http://github.com/mojombo/jekyll). They consist of a preambel written in YAML (also called YAML front matter), and some content in the format you prefer, e.g. Textile. This enables you to write documents in your favorite editor and access the content and metadata of these in your Ruby scripts.\n"
34
+ prerelease: false
35
+ version_requirements: *2156885300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2156884840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *2156884840
47
+ description: ! ' DocumentMapper is an object mapper for plain text documents. The
48
+ documents look like the ones used in jekyll (http://github.com/mojombo/jekyll).
49
+ They consist of a preambel written in YAML (also called YAML front matter), and
50
+ some content in the format you prefer, e.g. Textile. This enables you to write documents
51
+ in your favorite editor and access the content and metadata of these in your Ruby
52
+ scripts.
53
+
54
+ '
38
55
  email: ralph@rvdh.de
39
56
  executables: []
40
-
41
57
  extensions: []
42
-
43
58
  extra_rdoc_files: []
44
-
45
- files:
59
+ files:
46
60
  - LICENSE
47
61
  - README.textile
48
62
  - lib/document_mapper/attribute_methods.rb
@@ -66,30 +80,26 @@ files:
66
80
  - test/test_base.rb
67
81
  homepage: http://github.com/ralph/document_mapper
68
82
  licenses: []
69
-
70
83
  post_install_message:
71
84
  rdoc_options: []
72
-
73
- require_paths:
85
+ require_paths:
74
86
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
76
88
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
81
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
94
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
87
99
  requirements: []
88
-
89
100
  rubyforge_project:
90
- rubygems_version: 1.8.2
101
+ rubygems_version: 1.8.5
91
102
  signing_key:
92
103
  specification_version: 3
93
104
  summary: DocumentMapper is an object mapper for plain text documents.
94
105
  test_files: []
95
-