Sha256: b26cda2145ebd03842c3a94fd89615ae49ef7c55675a74dec8f0262ff55a6d77

Contents?: true

Size: 1007 Bytes

Versions: 76

Compression:

Stored size: 1007 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

    def to_s
      "#{self.class}[#{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

76 entries across 76 versions & 2 rubygems

Version Path
eac_tools-0.70.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.70.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.69.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.69.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.68.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.67.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.67.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.66.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.65.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.65.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.64.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.63.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.62.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.62.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.61.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.61.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.60.3 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.60.2 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.60.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.60.0 sub/eac_config/lib/eac_config/yaml_file_node.rb