Sha256: 508209ed3d8b8a2ce8ac5c2eea68e1187fd42c4e9f804f8d1374ab4c32dbe784

Contents?: true

Size: 954 Bytes

Versions: 59

Compression:

Stored size: 954 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
    enable_simple_cache

    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 persist_data(new_data)
      path.parent.mkpath
      ::EacRubyUtils::Yaml.dump_file(path, new_data)
      reset_cache(:data)
    end

    def url
      ::Addressable::URI.parse("file://#{path.expand_path}")
    end

    private

    def data_uncached
      r = nil
      if path.file?
        r = ::EacRubyUtils::Yaml.load_file(path)
      elsif path.exist?
        raise("\"#{path}\" is a not a file")
      end

      r.is_a?(::Hash) ? r : {}
    end
  end
end

Version data entries

59 entries across 59 versions & 3 rubygems

Version Path
eac_tools-0.25.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.11.0 lib/eac_config/yaml_file_node.rb
eac_tools-0.24.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.24.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.23.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.22.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.21.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.20.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.19.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.18.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.17.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.16.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.16.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.15.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.14.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.10.0 lib/eac_config/yaml_file_node.rb
eac_tools-0.13.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.12.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.11.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.11.0 sub/eac_config/lib/eac_config/yaml_file_node.rb