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
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 |
# 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) } if .all? { |_tag_name, tag_value| tag_value.empty? } result = .each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { || q = "SELECT value FROM tags " \ "WHERE %s;" % .map { |tag_name, _tag_value| glob?(tag_name) ? "LOWER(name) GLOB LOWER(?)" : "name = ?" }.join(" OR ") execute(q, .map { |tag_name, _tag_value| tag_name }).map { |value| [value] } } else result = .each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2).flat_map { || q = "SELECT value FROM tags " \ "WHERE %s;" % .map { |tag_name, tag_value| (glob?(tag_name) or glob?(tag_value)) ? "( 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
39 40 41 |
# File 'lib/hotdog/commands/tags.rb', line 39 def () STDOUT.print(format(, fields: ["tag"])) end |