Sha256: c794b79b0bf2711e630d39706c5dc191562bc3dd7977f7e31c819cc969556d15
Contents?: true
Size: 883 Bytes
Versions: 95
Compression:
Stored size: 883 Bytes
Contents
# frozen_string_literal: true module Orchestration class Settings def initialize(path) @path = path @dirty = false @exist = File.exist?(path) end def get(identifier) identifier.to_s.split('.').reduce(config) do |result, key| (result || {}).fetch(key) end rescue KeyError nil end def set(identifier, val) *keys, setting_key = identifier.to_s.split('.') new_config = config || {} parent = keys.reduce(new_config) { |result, key| result[key] ||= {} } parent[setting_key] = val @dirty ||= config != new_config File.write(@path, new_config.to_yaml) end def dirty? @dirty end def exist? @exist end private def config File.write(@path, {}.to_yaml) unless File.exist?(@path) YAML.safe_load(File.read(@path)) end end end
Version data entries
95 entries across 95 versions & 1 rubygems