class Plister::Exporter

Attributes

path[R]

Public Class Methods

new(path = nil) click to toggle source
# File lib/plister/exporter.rb, line 5
def initialize(path = nil)
  @path = path || "/Users/#{Plister.user}/.osx.yml"
end

Public Instance Methods

export() click to toggle source
# File lib/plister/exporter.rb, line 9
def export
  File.write path, to_s
end
to_s() click to toggle source
# File lib/plister/exporter.rb, line 13
def to_s
  Psych.dump(preferences)
end

Private Instance Methods

paths() click to toggle source
# File lib/plister/exporter.rb, line 27
def paths
  @paths ||= types.map { |type, path| [type, Dir["#{path}/*.plist"]] }.to_h
end
preferences() click to toggle source
# File lib/plister/exporter.rb, line 31
def preferences
  @preferences ||= begin
    output = {}
    paths.each do |type, plist_paths|
      plists = plist_paths.map { |domain| Plist.new domain, type: type }
      plists.select!(&:readable?)
      output[type.to_s] = plists.map { |p| [p.domain, p.to_h] }.to_h
    end
    output
  end
end
types() click to toggle source
# File lib/plister/exporter.rb, line 19
def types
  @types ||= {
    system: '/Library/Preferences',
    user:   "/Users/#{Plister.user}/Library/Preferences",
    host:   "/Users/#{Plister.user}/Library/preferences/ByHost"
  }
end