Sha256: 34476dc1b0807ce62352ca46ad8ce2bc3aee4526da5dc15786f38eeaeeb2b796

Contents?: true

Size: 778 Bytes

Versions: 3

Compression:

Stored size: 778 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
    include ::EacConfig::Node

    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)
      reset_cache(:data)
    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

3 entries across 3 versions & 2 rubygems

Version Path
avm-tools-0.99.1 vendor/eac_config/lib/eac_config/yaml_file_node.rb
eac_config-0.3.0 lib/eac_config/yaml_file_node.rb
avm-tools-0.99.0 vendor/eac_config/lib/eac_config/yaml_file_node.rb