document_file 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +5 -2
- data/lib/document_file/base.rb +2 -2
- data/lib/document_file/version.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -8,6 +8,10 @@ http://github.com/mojombo/jekyll). They consist of a preambel written in YAML
|
|
8
8
|
(also called YAML front matter), and some content in the format you prefer,
|
9
9
|
e.g. Textile. Example:
|
10
10
|
|
11
|
+
documents/
|
12
|
+
|-foo.textile
|
13
|
+
|-bar.textile
|
14
|
+
|
11
15
|
!!!document starts in the following line.
|
12
16
|
---
|
13
17
|
id: 1
|
@@ -22,10 +26,9 @@ I like the flowers.
|
|
22
26
|
Can be abstracted like this:
|
23
27
|
|
24
28
|
class MyDocument < DocumentFile::Base
|
29
|
+
self.documents_dir = './documents'
|
25
30
|
end
|
26
31
|
|
27
|
-
MyDocument.documents_dir = './documents'
|
28
|
-
|
29
32
|
# You now have dynamic finders:
|
30
33
|
doc = MyDocument.find_by_title("The shizzle!") # => returns the document
|
31
34
|
doc = MyDocument.find_by_number_of_foos(42) # => returns the document
|
data/lib/document_file/base.rb
CHANGED
@@ -32,7 +32,7 @@ module DocumentFile
|
|
32
32
|
def self.reload!
|
33
33
|
if File.directory?(@@documents_dir)
|
34
34
|
file_paths = Dir.glob("#{@@documents_dir}/*.*")
|
35
|
-
@@documents = file_paths.map { |file_path| self.new
|
35
|
+
@@documents = file_paths.map { |file_path| self.new file_path }
|
36
36
|
else
|
37
37
|
[]
|
38
38
|
end
|
@@ -99,7 +99,7 @@ module DocumentFile
|
|
99
99
|
|
100
100
|
def self.method_missing(method_name, *args)
|
101
101
|
self.all unless @@documents
|
102
|
-
super
|
102
|
+
respond_to?(method_name) ? self.send(method_name, *args) : super
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|