Sha256: c5f4752632cd8a8081e4bc7870a02578ec1611a963ba1aa2e6d64b0472e80359

Contents?: true

Size: 978 Bytes

Versions: 84

Compression:

Stored size: 978 Bytes

Contents

module Terraspace::Plugin::Helper
  module Interface
    extend ActiveSupport::Concern

    # Useful for plugin helpers. Can check this only run logic after dependency resolution.
    def resolved?
      !!@mod.resolved
    end

    class_methods do
      @@helper_cache = {}
      # This method is useful to avoid double call of heavy processing logic for tfvars,
      # since the tfvars files get evaluated twice.
      # Note: Not setting any cache or doing any logic unless resolved.
      def cache_helper(meth)
        uncached_meth = "uncached_#{meth}"
        alias_method(uncached_meth, meth)
        define_method(meth) do |*args|
          return unless resolved? # return nil in first unresolved pass
          id = Marshal.dump([meth] + args)
          exist = @@helper_cache.key?(id)
          if exist
            @@helper_cache[id]
          else
            @@helper_cache[id] = send(uncached_meth, *args)
          end
        end
      end
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.16 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.15 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.14 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.13 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.12 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.11 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.10 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.9 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.8 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.7 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.6 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.5 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.4 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.3 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.2 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.1 lib/terraspace/plugin/helper/interface.rb
terraspace-2.2.0 lib/terraspace/plugin/helper/interface.rb
terraspace-2.1.7 lib/terraspace/plugin/helper/interface.rb
terraspace-2.1.6 lib/terraspace/plugin/helper/interface.rb