Class: Hotdog::Commands::Tags
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Hotdog::Commands::Tags
- Defined in:
- lib/hotdog/commands/tags.rb
Instance Attribute Summary
Attributes inherited from BaseCommand
#application, #logger, #options, #persistent_db_path
Instance Method Summary collapse
Methods inherited from BaseCommand
#define_options, #execute, #fixed_string?, #initialize, #parse_options, #reload, #use_fallback?
Constructor Details
This class inherits a constructor from Hotdog::Commands::BaseCommand
Instance Method Details
#run(args = [], options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hotdog/commands/tags.rb', line 6 def run(args=[], ={}) if args.empty? result = execute("SELECT name, value FROM tags").map { |name, value| [join_tag(name, value)] } (result) else = args.map { |tag| split_tag(tag) } sqlite_limit_compound_select = [:sqlite_limit_compound_select] || SQLITE_LIMIT_COMPOUND_SELECT if .all? { |_tagname, tagvalue| tagvalue.empty? } result = .each_slice(sqlite_limit_compound_select).flat_map { || q = "SELECT value FROM tags " \ "WHERE %s;" % .map { |tagname, _tagvalue| glob?(tagname) ? "LOWER(name) GLOB LOWER(?)" : "name = ?" }.join(" OR ") execute(q, .map { |tagname, _tagvalue| tagname }).map { |value| [value] } } else result = .each_slice(sqlite_limit_compound_select / 2).flat_map { || q = "SELECT value FROM tags " \ "WHERE %s;" % .map { |tagname, tagvalue| (glob?(tagname) or glob?(tagvalue)) ? "( LOWER(name) GLOB LOWER(?) AND LOWER(value) GLOB LOWER(?) )" : "( name = ? AND value = ? )" }.join(" OR ") execute(q, ).map { |value| [value] } } end if result.empty? STDERR.puts("no match found: #{args.join(" ")}") exit(1) else (result) logger.info("found %d tag(s)." % result.length) if result.length < args.length STDERR.puts("insufficient result: #{args.join(" ")}") exit(1) end end end end |
#show_tags(tags) ⇒ Object
40 41 42 |
# File 'lib/hotdog/commands/tags.rb', line 40 def () STDOUT.print(format(, fields: ["tag"])) end |