Class: SysPref

Inherits:
Object
  • Object
show all
Defined in:
lib/iated/sys_pref.rb

Overview

Class to wrap the system preferences for the user.

This either uses Java System Preferences (if production) or an in-memory store (if testing).

Defined Under Namespace

Classes: FakeStore, JavaStore

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filename_pref(name, default) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/iated/sys_pref.rb', line 86

def self.filename_pref name, default
  preference_names << name
  jpref_name = name.to_s.upcase

  define_method name do
    Pathname.new store.get(jpref_name, send(default))
  end

  define_method "#{name}=".to_sym do |path|
    path = path.to_s.sub(/^~\//, home + '/')
    store.put(jpref_name, path)
    return nil
  end
end

.integer_pref(name, default) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/iated/sys_pref.rb', line 72

def self.integer_pref name, default
  preference_names << name
  jpref_name = name.to_s.upcase

  define_method name do
    store.getInt(jpref_name, send(default))
  end

  define_method "#{name}=".to_sym do |value|
    store.putInt(jpref_name, value.to_i)
    return nil
  end
end

.preference_namesObject



68
69
70
# File 'lib/iated/sys_pref.rb', line 68

def self.preference_names
  @preference_names ||= []
end

Instance Method Details

#homeString

User’s home directory

Returns:

  • (String)


115
116
117
118
119
120
121
# File 'lib/iated/sys_pref.rb', line 115

def home
  if RUBY_ENGINE == 'jruby'
    java.lang.System.getProperty("user.home")
  else
    ENV['HOME']
  end
end

#resetnil

Resets the preferences module

Returns:

  • (nil)


107
108
109
110
111
# File 'lib/iated/sys_pref.rb', line 107

def reset
  @test_dir.rmtree unless @test_dir.nil?
  @test_dir = nil
  @store = nil
end