Class: Settings

Inherits:
NSUserDefaults
  • Object
show all
Defined in:
lib/project/settings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Settings

Returns a new instance of Settings.


21
22
23
# File 'lib/project/settings.rb', line 21

def initialize(name)
  @name = name.to_s
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


2
3
4
# File 'lib/project/settings.rb', line 2

def name
  @name
end

#valueObject

Returns the value of attribute value


3
4
5
# File 'lib/project/settings.rb', line 3

def value
  @value
end

Class Method Details

.clearObject


17
18
19
# File 'lib/project/settings.rb', line 17

def self.clear
  NSUserDefaults.standardUserDefaults.setPersistentDomain(NSDictionary.dictionary, forName: NSBundle.mainBundle.bundleIdentifier)
end

.destroy(name) ⇒ Object


13
14
15
# File 'lib/project/settings.rb', line 13

def self.destroy(name)
  new(name).destroy
end

.get(name) ⇒ Object


5
6
7
# File 'lib/project/settings.rb', line 5

def self.get(name)
  new(name).fetch.value
end

.set(name, value) ⇒ Object


9
10
11
# File 'lib/project/settings.rb', line 9

def self.set(name, value)
  new(name).tap{|s| s.value = value; s.save }.value
end

Instance Method Details

#destroyObject


35
36
37
38
39
# File 'lib/project/settings.rb', line 35

def destroy
  self.value = nil
  NSUserDefaults.standardUserDefaults.removeObjectForKey name
  save
end

#fetchObject


30
31
32
33
# File 'lib/project/settings.rb', line 30

def fetch
  self.value = NSUserDefaults.standardUserDefaults[name]
  self
end

#saveObject


25
26
27
28
# File 'lib/project/settings.rb', line 25

def save
  NSUserDefaults.standardUserDefaults[name] = self.value
  NSUserDefaults.standardUserDefaults.synchronize
end