document_mapper 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/document_mapper/attribute_methods.rb +4 -4
- data/lib/document_mapper/core_ext/symbol.rb +6 -0
- data/lib/document_mapper/document.rb +8 -6
- data/lib/document_mapper/query.rb +3 -4
- data/lib/document_mapper/version.rb +1 -1
- data/test/document_mapper/document_mapper_test.rb +4 -0
- data/test/test_base.rb +2 -0
- metadata +29 -12
@@ -3,10 +3,10 @@ module DocumentMapper
|
|
3
3
|
module Read
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
included do
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
# included do
|
7
|
+
# # Undefine id so it can be used as an attribute name
|
8
|
+
# undef_method(:id) if method_defined?(:id)
|
9
|
+
# end
|
10
10
|
|
11
11
|
module ClassMethods
|
12
12
|
def define_read_method(attr_name)
|
@@ -8,7 +8,7 @@ module DocumentMapper
|
|
8
8
|
include ToHtml
|
9
9
|
include YamlParsing
|
10
10
|
|
11
|
-
attr_accessor :attributes, :content
|
11
|
+
attr_accessor :attributes, :content
|
12
12
|
|
13
13
|
included do
|
14
14
|
@@documents = []
|
@@ -26,7 +26,7 @@ module DocumentMapper
|
|
26
26
|
|
27
27
|
def reload
|
28
28
|
self.reset
|
29
|
-
self.directory = @@directory
|
29
|
+
self.directory = @@directory.path
|
30
30
|
end
|
31
31
|
|
32
32
|
def from_file(file_path)
|
@@ -47,7 +47,7 @@ module DocumentMapper
|
|
47
47
|
self.reset
|
48
48
|
@@directory = Dir.new File.expand_path(new_directory)
|
49
49
|
@@directory.each do |file|
|
50
|
-
next if file[0] == '.'
|
50
|
+
next if file[0,1] == '.'
|
51
51
|
self.from_file [@@directory.path, file].join('/')
|
52
52
|
end
|
53
53
|
end
|
@@ -55,7 +55,7 @@ module DocumentMapper
|
|
55
55
|
def select(options = {})
|
56
56
|
documents = @@documents.dup
|
57
57
|
options[:where].each do |selector, selector_value|
|
58
|
-
documents.select
|
58
|
+
documents = documents.select do |document|
|
59
59
|
next unless document.attributes.has_key? selector.attribute
|
60
60
|
document_value = document.send(selector.attribute)
|
61
61
|
operator = OPERATOR_MAPPING[selector.operator]
|
@@ -66,10 +66,12 @@ module DocumentMapper
|
|
66
66
|
if options[:order_by].present?
|
67
67
|
order_attribute = options[:order_by].keys.first
|
68
68
|
asc_or_desc = options[:order_by].values.first
|
69
|
-
documents.select
|
69
|
+
documents = documents.select do |document|
|
70
70
|
document.attributes.include? order_attribute
|
71
71
|
end
|
72
|
-
documents.sort_by
|
72
|
+
documents = documents.sort_by do |document|
|
73
|
+
document.send order_attribute
|
74
|
+
end
|
73
75
|
documents.reverse! if asc_or_desc == :desc
|
74
76
|
end
|
75
77
|
|
@@ -6,9 +6,8 @@ module DocumentMapper
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def where(constraints_hash)
|
9
|
-
|
10
|
-
|
11
|
-
symbol_hash = constraints_hash.reject &differentiator
|
9
|
+
selector_hash = constraints_hash.reject { |key, value| !key.is_a? Selector }
|
10
|
+
symbol_hash = constraints_hash.reject { |key, value| key.is_a? Selector }
|
12
11
|
symbol_hash.each do |attribute, value|
|
13
12
|
selector = Selector.new(:attribute => attribute, :operator => 'equal')
|
14
13
|
selector_hash.update({ selector => value })
|
@@ -43,7 +42,7 @@ module DocumentMapper
|
|
43
42
|
def all
|
44
43
|
result = @model.select(:where => @where, :order_by => @order_by)
|
45
44
|
if @offset.present?
|
46
|
-
result = result.last(result.size - @offset)
|
45
|
+
result = result.last([result.size - @offset, 0].max)
|
47
46
|
end
|
48
47
|
if @limit.present?
|
49
48
|
result = result.first(@limit)
|
@@ -121,6 +121,10 @@ describe MyDocument do
|
|
121
121
|
it 'should support offset and limit at the same time' do
|
122
122
|
assert_equal_set [2,3], MyDocument.order_by(:id).offset(1).limit(2).all.map(&:id)
|
123
123
|
end
|
124
|
+
|
125
|
+
it 'should not freak out about an offset higher than the document count' do
|
126
|
+
assert_equal_set [], MyDocument.order_by(:id).offset(5).all
|
127
|
+
end
|
124
128
|
end
|
125
129
|
|
126
130
|
describe 'resetting the MyDocument class' do
|
data/test/test_base.rb
CHANGED
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.
|
4
|
+
version: 0.1.5
|
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-
|
12
|
+
date: 2011-07-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156281780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156281780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &2156280460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156280460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &2156278980 !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: *
|
46
|
+
version_requirements: *2156278980
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: tilt
|
49
|
-
requirement: &
|
49
|
+
requirement: &2156278120 !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: *
|
57
|
+
version_requirements: *2156278120
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: RedCloth
|
60
|
-
requirement: &
|
60
|
+
requirement: &2156277280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,18 @@ dependencies:
|
|
65
65
|
version: 4.2.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2156277280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: &2156276220 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.3.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2156276220
|
69
80
|
description: ! ' DocumentMapper is an object mapper for plain text documents. The
|
70
81
|
documents look like the ones used in jekyll (http://github.com/mojombo/jekyll).
|
71
82
|
They consist of a preambel written in YAML (also called YAML front matter), and
|
@@ -113,12 +124,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
124
|
- - ! '>='
|
114
125
|
- !ruby/object:Gem::Version
|
115
126
|
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: 3820388701645222296
|
116
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
131
|
none: false
|
118
132
|
requirements:
|
119
133
|
- - ! '>='
|
120
134
|
- !ruby/object:Gem::Version
|
121
135
|
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: 3820388701645222296
|
122
139
|
requirements: []
|
123
140
|
rubyforge_project:
|
124
141
|
rubygems_version: 1.8.5
|