Sha256: b3036bd01184bf25a5692565745aa3976ef0c743016a3a8a5ad9a11d2ed081d3
Contents?: true
Size: 946 Bytes
Versions: 31
Compression:
Stored size: 946 Bytes
Contents
# frozen_string_literal: true require 'addressable' require 'eac_config/node' require 'eac_ruby_utils/core_ext' require 'eac_ruby_utils/yaml' module EacConfig class YamlFileNode require_sub __FILE__ include ::EacConfig::Node class << self def from_uri(uri) return new(uri.to_addressable.path) if uri.to_addressable.scheme == 'file' end end common_constructor :path do self.path = path.to_pathname end def data @data ||= ::EacRubyUtils::Yaml.load_file(assert_path) || {} end def persist_data(new_data) path.parent.mkpath ::EacRubyUtils::Yaml.dump_file(path, new_data) @data = nil end def url ::Addressable::URI.parse("file://#{path.expand_path}") end private def assert_path unless path.file? raise("\"#{path}\" is a not a file") if path.exist? persist_data({}) end path end end end
Version data entries
31 entries across 31 versions & 3 rubygems