module Dle::Application::Filter

Public Instance Methods

apply_filter(collection, file) click to toggle source
# File lib/dle/application/filter.rb, line 8
def apply_filter collection, file
  app = @app
  eval File.read(file), binding, file
  collection
end
filter_script(name) click to toggle source
# File lib/dle/application/filter.rb, line 4
def filter_script name
  File.expand_path("~/.dle/#{name}.rb")
end
permute_script(collection, file = nil) click to toggle source
# File lib/dle/application/filter.rb, line 14
def permute_script collection, file = nil
  file ||= "#{Dir.tmpdir}/#{SecureRandom.urlsafe_base64}"
  FileUtils.mkdir(File.dirname(file)) if !File.exist?(File.dirname(file))
  if !File.exist?(file) || File.read(file).strip.empty?
    File.open(file, "w") {|f| f.puts("# Permute your collection, same as with the selector script filters.") }
  end
  system "#{cfg :application, :editor} #{file}"
  eval File.read(file), binding, file
  collection
end
record_filter(file = nil) click to toggle source
# File lib/dle/application/filter.rb, line 25
def record_filter file = nil
  file ||= "#{Dir.tmpdir}/#{SecureRandom.urlsafe_base64}.rb"
  FileUtils.mkdir(File.dirname(file)) if !File.exist?(File.dirname(file))
  if !File.exist?(file) || File.read(file).strip.empty?
    FileUtils.cp("#{ROOT}/lib/dle/application/filter.tpl", file)
  end
  open_editor(file)
  file
end