module Openmeta

Constants

VERSION

Attributes

error[W]
ui[W]

Public Class Methods

add_tags(new_tags, to_files) click to toggle source
# File lib/openmeta/macruby.rb, line 55
def add_tags(new_tags, to_files)
  to_files = fu_list(to_files)

  to_files.each { |file|
    existing_tags = get_tags(file)

    if e = OpenMeta.addUserTags(new_tags, path:file)
      raise Openmeta::ObjCError, e.inspect
    end

    OpenMetaPrefs.updatePrefsRecentTags(existing_tags, newTags:new_tags)
  }
end
clear(files) click to toggle source
# File lib/openmeta/macruby.rb, line 113
def clear(files)
  files = fu_list(files)
  files.each { |file|
    set_tags([], file)
    set_rating(0.0, file)
  }
end
clone(from_file, to_files) click to toggle source
# File lib/openmeta/macruby.rb, line 97
def clone(from_file, to_files)

  unless File.exist?(from_file)
    raise Openmeta::PathError, "#{from_file} does not exist!"
  end

  tags = get_tags(from_file)
  rating = get_rating(from_file)

  to_files = fu_list(to_files)
  to_files.each { |file|
    set_tags(tags, file) unless (tags == nil or tags.empty?)
    set_rating(rating, file) unless rating == 0.0
  }
end
error() click to toggle source
# File lib/openmeta/macruby.rb, line 27
def error
  @error ||= Pointer.new(:id)
end
get_rating(path) click to toggle source
# File lib/openmeta/macruby.rb, line 82
def get_rating(path)
  rating = OpenMeta.getRating(File.expand_path(path), error:error)
  if error.value
    raise Openmeta::ObjCError, error.value.inspect
  end
  rating
end
get_tags(path) click to toggle source

note returned array are frozen

# File lib/openmeta/macruby.rb, line 32
def get_tags(path)
  tags = OpenMeta.getUserTags(File.expand_path(path), error:error)
  if error.value
    raise Openmeta::ObjCError, error.value.inspect
  end
  tags
end
recent_tags() click to toggle source
# File lib/openmeta/macruby.rb, line 122
def recent_tags
  OpenMetaPrefs.recentTags
end
remove_tags(tags, from_files) click to toggle source
# File lib/openmeta/macruby.rb, line 69
def remove_tags(tags, from_files)
  from_files = fu_list(from_files)

  return if tags.empty?

  from_files.each { |file|
    existing_tags = get_tags(file) # frozen array
    next if existing_tags.nil? or existing_tags.empty?

    set_tags(existing_tags - tags, file)
  }
end
set_rating(rating, path) click to toggle source
# File lib/openmeta/macruby.rb, line 90
def set_rating(rating, path)
  e = OpenMeta.setRating(rating, path:File.expand_path(path))
  if e
    raise Openmeta::ObjCError, e.inspect
  end
end
set_tags(new_tags, path) click to toggle source
# File lib/openmeta/macruby.rb, line 40
def set_tags(new_tags, path)
  path = File.expand_path(path)

  existing_tags = OpenMeta.getUserTags(path, error:error)
  if error.value
    raise Openmeta::ObjCError, error.value.inspect
  end

  if e = OpenMeta.setUserTags(new_tags, path:path)
    raise Openmeta::ObjCError, e.inspect
  end

  OpenMetaPrefs.updatePrefsRecentTags(existing_tags, newTags:new_tags)
end
ui() click to toggle source
# File lib/openmeta/macruby.rb, line 23
def ui
  @ui ||= UI.new
end
with_friendly_errors() { || ... } click to toggle source
# File lib/openmeta/friendly_errors.rb, line 2
def self.with_friendly_errors
  begin
    yield
  rescue Openmeta::OpenmetaError => e
    Openmeta.ui.error e.message
    Openmeta.ui.debug e.backtrace.join("\n")
    exit e.status_code
  rescue Interrupt => e
    Openmeta.ui.error "\nQuitting..."
    Openmeta.ui.debug e.backtrace.join("\n")
    exit 1
  rescue SystemExit => e
    exit e.status
  rescue Exception => e
    Openmeta.ui.error(
      "Unfortunately, a fatal error has occurred. Please see the Openmeta \n" \
      "troubleshooting documentation. Thanks!\n  #{e.inspect} #{e.backtrace.join("\n")}\n")
    raise e
  end
end