Module: Ciridiri::Finders
- Included in:
- Page
- Defined in:
- lib/ciridiri/finders.rb
Instance Method Summary collapse
-
#all ⇒ Object
Return an array of all ‘Page`s excluding backups.
-
#find_by_uri(uri) ⇒ Object
Convert ‘uri` to a path and return a new `Page` instance if the corresponding file exists.
-
#find_by_uri_or_empty(uri) ⇒ Object
Return a new empty ‘Page` instance if the corresponding file doesn’t exists.
Instance Method Details
#all ⇒ Object
Return an array of all ‘Page`s excluding backups
16 17 18 19 20 21 22 |
# File 'lib/ciridiri/finders.rb', line 16 def all Dir.chdir(content_dir) do files = Dir.glob(File.join("**", "*#{Ciridiri::SOURCE_FILE_EXT}")). delete_if {|p| p =~ Regexp.new("\\.[0-9]+\\#{Ciridiri::SOURCE_FILE_EXT}$")} files.collect {|f| Page.new(uri_from_path(f), File.open(f, 'r') {|b| b.read})} end end |
#find_by_uri(uri) ⇒ Object
Convert ‘uri` to a path and return a new `Page` instance if the corresponding file exists. Return nil otherwise
5 6 7 8 |
# File 'lib/ciridiri/finders.rb', line 5 def find_by_uri(uri) content_path = path_from_uri(uri) File.exists?(content_path) ? Page.new(uri, File.open(content_path).read) : nil end |