Module: TmsuFileAPI
- Included in:
- TmsuModel, TmsuRuby::TmsuFile
- Defined in:
- lib/tmsu_file_db.rb
Instance Method Summary collapse
- #build_tag_arg(obj) ⇒ Object
- #files(tag_obj) ⇒ Object
- #merge_tag(source, dest) ⇒ Object
- #persisted? ⇒ Boolean
- #require_persisted ⇒ Object
- #tag(tag_obj) ⇒ Object
- #tag_selector(tag_obj) ⇒ Object
- #tags ⇒ Object
- #untag(tag_list) ⇒ Object
- #untag_selector(tag_obj) ⇒ Object
Instance Method Details
#build_tag_arg(obj) ⇒ Object
307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/tmsu_file_db.rb', line 307 def build_tag_arg obj case obj when Array obj.map { |x| %{"#{x}"} }.join " " when Hash obj.map do |k,v| %{"#{k}=#{v}"} end.join " " else %{"#{obj}"} end end |
#files(tag_obj) ⇒ Object
339 340 341 |
# File 'lib/tmsu_file_db.rb', line 339 def files(tag_obj) system("tmsu files --path #{path} #{build_tag_arg tag_obj }").split("\n") end |
#merge_tag(source, dest) ⇒ Object
330 331 332 333 334 335 336 337 |
# File 'lib/tmsu_file_db.rb', line 330 def merge_tag(source, dest) source_files = files source dest_files = files dest raise(ArgumentError, "#{source} tag not found") if source_files.empty? raise(ArgumentError, "#{dest} tag not found") if dest_files.empty? system("tmsu merge #{source} #{dest}") source_files end |
#persisted? ⇒ Boolean
272 273 274 275 |
# File 'lib/tmsu_file_db.rb', line 272 def persisted? return super if defined?(super) File.exists? path end |
#require_persisted ⇒ Object
289 290 291 292 293 |
# File 'lib/tmsu_file_db.rb', line 289 def require_persisted unless persisted? raise(RuntimeError, "called tags on unsaved record. path: #{path}") end end |
#tag(tag_obj) ⇒ Object
301 302 303 304 305 |
# File 'lib/tmsu_file_db.rb', line 301 def tag tag_obj `touch #{path}` system %{tmsu tag #{path} #{build_tag_arg tag_obj}} end |
#tag_selector(tag_obj) ⇒ Object
320 321 322 323 |
# File 'lib/tmsu_file_db.rb', line 320 def tag_selector(tag_obj) system "tmsu tag --tags '#{build_tag_arg tag_obj}' #{path}" files tag_obj end |
#tags ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/tmsu_file_db.rb', line 277 def return {} unless persisted? delimiter = /(?<!\\)\s/ cmd_res = system("tmsu tags #{path}") cmd_res.chomp.split(delimiter)[1..-1].reduce({}) do |res, tag| key, val = tag.split("=").map do |str| str end res.tap { res[key] = val } end end |
#untag(tag_list) ⇒ Object
295 296 297 298 299 |
# File 'lib/tmsu_file_db.rb', line 295 def untag tag_list `touch #{path}` system "tmsu untag #{path} #{tag_list}" end |
#untag_selector(tag_obj) ⇒ Object
325 326 327 328 |
# File 'lib/tmsu_file_db.rb', line 325 def untag_selector(tag_obj) system "tmsu untag --tags '#{build_tag_arg tag_obj}' #{path}" files tag_obj end |