Module: Filetter

Defined in:
lib/filetter.rb,
lib/modes/flickr.rb,
lib/modes/sample.rb,
lib/modes/twitter.rb,
lib/filetter/version.rb,
lib/filetter/observer.rb,
lib/filetter/file_info.rb

Defined Under Namespace

Classes: FileInfo, Observer

Constant Summary collapse

VERSION =
'0.2.8'

Class Method Summary collapse

Class Method Details

.add_hook(*args, &block) ⇒ Object



79
80
81
# File 'lib/filetter.rb', line 79

def add_hook(*args, &block)
  Observer.instance.add_hook(*args, &block)
end

.open_brawser(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/modes/flickr.rb', line 8

def self.open_brawser(url)
  case RUBY_PLATFORM
  when /linux/
    system 'firefox', url
  when /mswin(?!ce)|mingw|bccwin/
    system 'explorer', url
  else
    system 'open', url
  end
end

.run(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/filetter.rb', line 16

def run(options = {})
  patterns = []
  interval = 2
  debug = false
  mode = nil
  load_file = '.filetter'
  work_dir = nil
  help = nil
  list = false

  OptionParser.new do |opt|
    opt.version = VERSION
    opt.program_name = self.to_s
    opt.on('-m', '--mode=mode', 'Run mode'                                  ) {|v| mode = v       }
    opt.on('-f', '--loadfile=file', 'File to load'                          ) {|v| load_file = v  }
    opt.on('-c', '--cd=directory', 'cd to directory'                        ) {|v| work_dir = v   }
    opt.on('-p', '--pattern=pattern', 'Pattern of target files'             ) {|v| patterns << v  }
    opt.on('-i', '--interval=interval', 'Interval of check files', Integer  ) {|v| interval = v   }
    opt.on('-d', '--debug', 'Enable debug mode'                             ) {|v| debug = true   }
    opt.on('-l', '--list', 'List up available modes'                        ) {|v| list = true    }
    opt.parse!(ARGV)
    help = opt.help
  end

  if work_dir
    Dir.chdir(work_dir)
    puts "=> cd to #{work_dir}"
  end

  patterns << './**/*' if patterns.empty?

  begin
    if mode.nil? && !File.exist?(load_file)
      if list
        puts Dir[File.dirname(__FILE__) + '/modes/*.rb'].map{|f|File.basename(f).gsub(/\.rb$/, '')}
        exit
      else
        puts help
        exit!
      end
    else
      if File.exist?(load_file)
        puts "=> load \"#{load_file}\""
        load load_file
      end
      if mode
        puts "=> Run as \"#{mode}\" mode"
        require "modes/#{mode}"
      end
    end
  rescue LoadError => e
    puts e
    raise if debug
    exit!
  rescue => e
    puts e
    raise if debug
    exit!
  end

  Observer.run({:patterns => patterns, :interval => interval, :debug => debug}.merge(options))
end