Class: MovieOrganizer::Settings

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

Overview

Simple class for YAML settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file = MovieOrganizer.config_file) ⇒ Settings

Returns a new instance of Settings.



12
13
14
# File 'lib/movie_organizer/settings.rb', line 12

def initialize(file = MovieOrganizer.config_file)
  @file = file
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/movie_organizer/settings.rb', line 10

def config
  @config
end

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

Instance Method Details

#[](key) ⇒ Object



26
27
28
29
# File 'lib/movie_organizer/settings.rb', line 26

def [](key)
  load
  config[key]
end

#[]=(key, value) ⇒ Object



31
32
33
34
# File 'lib/movie_organizer/settings.rb', line 31

def []=(key, value)
  load
  config[key] = value
end

#allObject



41
42
43
44
# File 'lib/movie_organizer/settings.rb', line 41

def all
  load
  config
end

#dataObject



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

def data
  load
  config
end

#loadObject



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

def load
  @config ||= YAML.load_file(file) || {}
  self
end

#saveObject



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

def save
  File.open(file, 'w') { |thefile| thefile.write(YAML.dump(config)) }
  self
end