Sha256: fc48835e61189417327e937e0f7a57eaf15538cde9d8f44556711b0bfee20d42

Contents?: true

Size: 1.48 KB

Versions: 68

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/require_sub'
require 'eac_ruby_utils/simple_cache'
require 'avm/instances/entries'

module Avm
  module Instances
    class Base
      enable_listable
      enable_simple_cache
      require_sub __FILE__, include_modules: true
      include ::Avm::Instances::Entries

      lists.add_string :access, :local, :ssh

      ID_PATTERN = /\A([a-z0-9]+(?:\-[a-z0-9]+)*)_(.+)\z/.freeze

      class << self
        def by_id(id)
          application_id, suffix = parse_id(id)
          require 'avm/instances/application'
          new(::Avm::Instances::Application.new(application_id), suffix)
        end

        private

        def parse_id(id)
          m = ID_PATTERN.match(id)
          return [m[1], m[2]] if m

          raise "ID Pattern no matched: \"#{id}\""
        end
      end

      common_constructor :application, :suffix do
        self.suffix = suffix.to_s
      end

      def id
        "#{application.id}_#{suffix}"
      end

      def to_s
        id
      end

      def host_env_uncached
        access = read_entry(:access, list: ::Avm::Instances::Base.lists.access.values)
        case access
        when 'local' then ::EacRubyUtils::Envs.local
        when 'ssh' then ::EacRubyUtils::Envs.ssh(read_entry('ssh.url'))
        else raise("Unmapped access value: \"#{access}\"")
        end
      end

      private

      def source_instance_uncached
        ::Avm::Instances::Base.by_id(source_instance_id)
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 3 rubygems

Version Path
avm-0.26.0 lib/avm/instances/base.rb
eac_tools-0.8.0 sub/avm/lib/avm/instances/base.rb
eac_tools-0.7.0 sub/avm/lib/avm/instances/base.rb
avm-0.25.0 lib/avm/instances/base.rb
eac_tools-0.6.0 sub/avm/lib/avm/instances/base.rb
eac_tools-0.5.0 sub/avm/lib/avm/instances/base.rb
avm-0.24.0 lib/avm/instances/base.rb
eac_tools-0.4.0 sub/avm/lib/avm/instances/base.rb
eac_tools-0.3.0 sub/avm/lib/avm/instances/base.rb
eac_tools-0.2.2 sub/avm/lib/avm/instances/base.rb
avm-0.23.0 lib/avm/instances/base.rb
avm-0.22.0 lib/avm/instances/base.rb
avm-tools-0.120.0 sub/avm/lib/avm/instances/base.rb
avm-0.21.0 lib/avm/instances/base.rb
avm-tools-0.119.0 sub/avm/lib/avm/instances/base.rb
avm-0.20.0 lib/avm/instances/base.rb
avm-tools-0.118.0 sub/avm/lib/avm/instances/base.rb
avm-tools-0.117.3 sub/avm/lib/avm/instances/base.rb
avm-tools-0.117.2 sub/avm/lib/avm/instances/base.rb
avm-tools-0.117.1 sub/avm/lib/avm/instances/base.rb