Sha256: c8ada84cac8917f29d14fb25a0c63c2e2fc7335c92dc761b23e36f32b295e39d

Contents?: true

Size: 1.14 KB

Versions: 36

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module Avm
  module Instances
    class Entry
      class << self
        def auto_value_method_name(suffix)
          "auto_#{suffix.to_s.gsub('.', '_')}"
        end
      end

      common_constructor :parent, :suffix, :options

      def auto_value
        parent.respond_to?(auto_value_method, true) ? parent.send(auto_value_method) : nil
      end

      def auto_value_method
        self.class.auto_value_method_name(suffix)
      end

      def full_path
        (parent.path_prefix + suffix_as_array).join('.')
      end

      def optional_value
        read(required: false, noinput: true) || auto_value
      end

      def read(extra_options = {})
        ::Avm.configs.read_entry(full_path, options.merge(extra_options))
      end

      def suffix_as_array
        if suffix.is_a?(::Array)
          suffix.dup
        else
          ::EacRubyUtils::PathsHash.parse_entry_key(suffix.to_s)
        end
      end

      def value
        optional_value || read
      end

      def write(value)
        ::Avm.configs.configs.write_entry(full_path, value)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
avm-tools-0.98.0 lib/avm/instances/entry.rb
avm-tools-0.97.0 lib/avm/instances/entry.rb
avm-tools-0.96.0 lib/avm/instances/entry.rb
avm-tools-0.95.0 lib/avm/instances/entry.rb
avm-tools-0.94.3 lib/avm/instances/entry.rb
avm-tools-0.94.2 lib/avm/instances/entry.rb
avm-tools-0.94.1 lib/avm/instances/entry.rb
avm-tools-0.94.0 lib/avm/instances/entry.rb
avm-tools-0.93.0 lib/avm/instances/entry.rb
avm-tools-0.92.0 lib/avm/instances/entry.rb
avm-tools-0.91.0 lib/avm/instances/entry.rb
avm-tools-0.90.0 lib/avm/instances/entry.rb
avm-tools-0.89.0 lib/avm/instances/entry.rb
avm-tools-0.88.0 lib/avm/instances/entry.rb
avm-tools-0.87.1 lib/avm/instances/entry.rb
avm-tools-0.87.0 lib/avm/instances/entry.rb
avm-tools-0.86.0 lib/avm/instances/entry.rb
avm-tools-0.85.1 lib/avm/instances/entry.rb
avm-tools-0.85.0 lib/avm/instances/entry.rb
avm-tools-0.84.0 lib/avm/instances/entry.rb