public
Rubygem
Description: A lightweight and flexible website management system.
Homepage: http://webby.rubyforge.org/
Clone URL: git://github.com/TwP/webby.git
Add :recursive option for Webby::PagesDB#find (for use with :in_directory)
bruce (author)
Mon Jan 28 20:26:27 -0800 2008
commit  b426aa8d6ec53dbfca56f84b9d9e0cd9c70211ed
tree    c54215b9c515b9c59bd1c2804cf16ab6dc22b292
parent  1e97204f721ee0482cbd7f2617f54a72bab8bb5f
...
98
99
100
101
102
103
 
 
 
 
 
 
 
 
 
 
 
104
105
106
...
111
112
113
114
 
115
116
117
118
119
120
121
122
123
 
124
125
 
126
127
128
...
98
99
100
 
 
 
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
119
120
121
 
122
123
 
124
125
126
127
128
129
 
130
131
 
132
133
134
135
0
@@ -98,9 +98,17 @@ class PagesDB
0
     opts = Hash === args.last ? args.pop : {}
0
     find_all = args.include? :all
0
 
0
- dir = opts.has_key?(:in_directory) ? opts.delete(:in_directory) : nil
0
- if dir && !@db.has_key?(dir)
0
- raise RuntimeError, "unknown directory '#{dir}'"
0
+ search = if (dir = opts.delete(:in_directory))
0
+ strategy = if opts.delete(:recursive)
0
+ lambda { |key| key =~ /^#{Regexp.escape(dir)}(?:\/|$)/ }
0
+ else
0
+ lambda { |key| key == dir }
0
+ end
0
+ matching_keys = @db.keys.select(&strategy)
0
+ raise RuntimeError, "unknown directory '#{dir}'" if matching_keys.empty?
0
+ matching_keys.map { |key| @db[key] }.flatten
0
+ else
0
+ self
0
     end
0
 
0
     block ||= lambda do |page|
0
@@ -111,18 +119,17 @@ class PagesDB
0
       end
0
       found
0
     end
0
-
0
+
0
     ary = []
0
- search = dir ? @db[dir] : self
0
     search.each do |page|
0
       if block.call(page)
0
         ary << page
0
         break unless find_all
0
       end
0
     end
0
-
0
+
0
     return ary if find_all
0
- return ary.first
0
+ return ary.first
0
   end
0
 
0
   # call-seq:

Comments

    No one has commented yet.