Class: MovieOrganizer::Settings
- Inherits:
-
Object
- Object
- MovieOrganizer::Settings
- Defined in:
- lib/movie_organizer/settings.rb
Overview
Simple class for YAML settings
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #all ⇒ Object
- #data ⇒ Object
-
#initialize(file = MovieOrganizer.config_file) ⇒ Settings
constructor
A new instance of Settings.
- #load ⇒ Object
- #save ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/movie_organizer/settings.rb', line 10 def config @config end |
#file ⇒ Object (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 |
#all ⇒ Object
41 42 43 44 |
# File 'lib/movie_organizer/settings.rb', line 41 def all load config end |
#data ⇒ Object
36 37 38 39 |
# File 'lib/movie_organizer/settings.rb', line 36 def data load config end |
#load ⇒ Object
16 17 18 19 |
# File 'lib/movie_organizer/settings.rb', line 16 def load @config ||= YAML.load_file(file) || {} self end |
#save ⇒ Object
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 |