Sha256: 5566369843ec6ff342be841e23b986416a9e3b8967240821c147f849f03c33e5

Contents?: true

Size: 720 Bytes

Versions: 2

Compression:

Stored size: 720 Bytes

Contents

# frozen_string_literal: true

require 'singleton'
require 'yaml'

#:nocov:
module MovieOrganizer
  # Simple class for YAML settings
  class Settings
    include Singleton

    attr_reader :file
    attr_reader :config

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

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

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

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

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

    def data
      load
      config
    end

    def all
      load
      config
    end
  end
end
#:nocov:

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
movie_organizer-1.0.2 lib/movie_organizer/settings.rb
movie_organizer-1.0.1 lib/movie_organizer/settings.rb