Module: Flunkey::Functions
- Included in:
- Server
- Defined in:
- lib/flunkey/functions.rb
Instance Method Summary collapse
Instance Method Details
#recognize(path) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/flunkey/functions.rb', line 3 def recognize(path) return if path.nil? path = Pathname.new(path) unless path === Pathname if path.relative? first_dir = path.to_s.split('/').first root = settings.paths.find{|p| p.basename.to_s == first_dir } return [root, (root.root? ? Pathname.new('/') : root.parent) + path] end root = settings.paths.find{|p| p.is_parent_of?(path) } [root, path] end |
#search(query) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/flunkey/functions.rb', line 15 def search(query) cmd = %w{/usr/bin/mdfind} settings.paths.each { |p| cmd << "-onlyin #{p}" } cmd << "\"#{query}\"" `#{cmd.join(' ')}`.lines.map{|l| recognize(l.strip) } end |