document_mapper 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ module DocumentMapper
11
11
  attr_accessor :attributes, :content
12
12
 
13
13
  included do
14
- @@documents = []
14
+ @documents = []
15
15
  end
16
16
 
17
17
  def ==(other_document)
@@ -21,12 +21,12 @@ module DocumentMapper
21
21
 
22
22
  module ClassMethods
23
23
  def reset
24
- @@documents = []
24
+ @documents = []
25
25
  end
26
26
 
27
27
  def reload
28
28
  self.reset
29
- self.directory = @@directory.path
29
+ self.directory = @directory.path
30
30
  end
31
31
 
32
32
  def from_file(file_path)
@@ -38,22 +38,22 @@ module DocumentMapper
38
38
  :file_path => File.expand_path(file_path)
39
39
  }
40
40
  document.read_yaml
41
- @@documents << document
41
+ @documents << document
42
42
  end
43
43
  end
44
44
 
45
45
  def directory=(new_directory)
46
46
  raise FileNotFoundError unless File.directory?(new_directory)
47
47
  self.reset
48
- @@directory = Dir.new File.expand_path(new_directory)
49
- @@directory.each do |file|
48
+ @directory = Dir.new File.expand_path(new_directory)
49
+ @directory.each do |file|
50
50
  next if file[0,1] == '.'
51
- self.from_file [@@directory.path, file].join('/')
51
+ self.from_file [@directory.path, file].join('/')
52
52
  end
53
53
  end
54
54
 
55
55
  def select(options = {})
56
- documents = @@documents.dup
56
+ documents = @documents.dup
57
57
  options[:where].each do |selector, selector_value|
58
58
  documents = documents.select do |document|
59
59
  next unless document.attributes.has_key? selector.attribute
@@ -95,19 +95,19 @@ module DocumentMapper
95
95
  end
96
96
 
97
97
  def all
98
- @@documents
98
+ @documents
99
99
  end
100
100
 
101
101
  def first
102
- @@documents.first
102
+ @documents.first
103
103
  end
104
104
 
105
105
  def last
106
- @@documents.last
106
+ @documents.last
107
107
  end
108
108
 
109
109
  def attributes
110
- @@documents.map(&:attributes).map(&:keys).flatten.uniq.sort
110
+ @documents.map(&:attributes).map(&:keys).flatten.uniq.sort
111
111
  end
112
112
  end
113
113
  end
@@ -1,3 +1,3 @@
1
1
  module DocumentMapper
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -336,6 +336,16 @@ EOS
336
336
  end
337
337
  end
338
338
 
339
+ describe 'multiple document classes' do
340
+ it 'can serve multiple document directories' do
341
+ MyDocument.directory = 'test/documents'
342
+ MyOtherDocument.directory = 'test/other_documents'
343
+
344
+ assert_equal 4, MyDocument.all.count
345
+ assert_equal 1, MyOtherDocument.all.count
346
+ end
347
+ end
348
+
339
349
  def sample_file_path_1
340
350
  'test/documents/2010-08-08-test-document-file.textile'
341
351
  end
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Some test document
3
+ ---
4
+
5
+ This is just some test document.
data/test/test_base.rb CHANGED
@@ -12,6 +12,10 @@ class MyDocument
12
12
  include DocumentMapper::Document
13
13
  end
14
14
 
15
+ class MyOtherDocument
16
+ include DocumentMapper::Document
17
+ end
18
+
15
19
  module MiniTest::Assertions
16
20
  def assert_equal_set exp, act, msg = nil
17
21
  msg = message(msg) { "Expected #{mu_pp(exp)}, not #{mu_pp(act)}" }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: document_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
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: 2011-09-14 00:00:00.000000000Z
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70138859185020 !ruby/object:Gem::Requirement
16
+ requirement: &70120929299440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70138859185020
24
+ version_requirements: *70120929299440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &70138859184180 !ruby/object:Gem::Requirement
27
+ requirement: &70120929298880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70138859184180
35
+ version_requirements: *70120929298880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70138859183360 !ruby/object:Gem::Requirement
38
+ requirement: &70120929298380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70138859183360
46
+ version_requirements: *70120929298380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tilt
49
- requirement: &70138859182700 !ruby/object:Gem::Requirement
49
+ requirement: &70120929297840 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70138859182700
57
+ version_requirements: *70120929297840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: RedCloth
60
- requirement: &70138859182100 !ruby/object:Gem::Requirement
60
+ requirement: &70120929297320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 4.2.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70138859182100
68
+ version_requirements: *70120929297320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
- requirement: &70138859181500 !ruby/object:Gem::Requirement
71
+ requirement: &70120929296820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 2.6.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70138859181500
79
+ version_requirements: *70120929296820
80
80
  description: ! ' DocumentMapper is an object mapper for plain text documents. The
81
81
  documents look like the ones used in jekyll (http://github.com/mojombo/jekyll).
82
82
  They consist of a preambel written in YAML (also called YAML front matter), and
@@ -111,6 +111,7 @@ files:
111
111
  - test/documents/2010-08-09-another-test-document.textile
112
112
  - test/documents/document_with_date_in_yaml.textile
113
113
  - test/documents/document_without_date.textile
114
+ - test/other_documents/2011-12-26-some-test-document.textile
114
115
  - test/test_base.rb
115
116
  homepage: http://github.com/ralph/document_mapper
116
117
  licenses: []
@@ -126,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  segments:
128
129
  - 0
129
- hash: 4508131542455826029
130
+ hash: 2393159709703028438
130
131
  required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  none: false
132
133
  requirements:
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  version: '0'
136
137
  segments:
137
138
  - 0
138
- hash: 4508131542455826029
139
+ hash: 2393159709703028438
139
140
  requirements: []
140
141
  rubyforge_project:
141
142
  rubygems_version: 1.8.10