Sha256: 887756ca0671358170d80b4dcf9e7f2a2b11cab21d740951633371fea514a25a

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

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
    compare_by :path

    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

    require_sub __FILE__, require_mode: :kernel
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
eac_tools-0.82.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.81.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.80.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.79.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.14.1 lib/eac_config/yaml_file_node.rb
eac_tools-0.78.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.77.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.77.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.76.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.76.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.75.2 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.75.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.75.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.74.1 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_tools-0.74.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.14.0 lib/eac_config/yaml_file_node.rb
eac_tools-0.73.0 sub/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.13.0 lib/eac_config/yaml_file_node.rb
eac_tools-0.72.0 sub/eac_config/lib/eac_config/yaml_file_node.rb