Class: Photostat::Query

Inherits:
Plugins::Base show all
Includes:
OSUtils
Defined in:
lib/photostat/plugins/03_query.rb

Instance Method Summary collapse

Methods included from OSUtils

#exec, #file_md5, #files_in_dir, #input, #partial_file_md5, #string_md5

Methods inherited from Plugins::Base

#activate!, #config, exposes, exposes_help, extended, #help, help_text, included, inherited, plugin_name, register_plugin

Instance Method Details

#listObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/photostat/plugins/03_query.rb', line 9

def list
  opts = Trollop::options do
    opt :visibility, "Specifies visibility of photos, choices are private, protected and public", :type => :string
    opt :sort, "Specify sort field, one example being 'created_at'", :type => :string
    opt :reverse, "Reverses output list", :type => :boolean
    opt :absolute, "Output absolute path", :type => :boolean
  end

  config = Photostat.config
  db = Photostat::DB.instance

  rs = db[:photos]
  rs = rs.where(:visibility => opts[:visibility]) if opts[:visibility]
  rs = rs.order(opts[:sort].to_sym) if opts[:sort]
  rs = rs.reverse if opts[:reverse]      

  rs.each do |obj|
    path = obj[:local_path]
    path = File.expand_path(File.join(config[:repository_path], path)) if opts[:absolute]
    puts path
  end
end