<commit_before>require 'memoist'
require 'stacker/differ'
require 'stacker/resolver'
require 'stacker/stack/component'

module Stacker
  class Stack
    class Parameters < Component

      extend Memoist

      # everything required by the template
      def template_definitions
        stack.template.local.fetch 'Parameters', {}
      end

      def region_defaults
        stack.region.defaults.fetch 'parameters', {}
      end

      # template defaults merged with region and stack-specific overrides
      def local
        region_defaults = stack.region.defaults.fetch 'parameters', {}

        template_defaults = Hash[
          template_definitions.select { |_, opts|
            opts.key?('Default')
          }.map { |name, opts|
            [name, opts['Default']]
          }
        ]

        available = region_defaults.merge(
          template_defaults.merge(
            stack.options.fetch 'parameters', {}
          )
        )

        available.slice *template_definitions.keys
      end

      def missing
        template_definitions.keys - local.keys
      end

      def remote
        client.parameters
      end
      memoize :remote

      def resolved
        resolver.resolved
      end
      memoize :resolved

      def resolver
        Resolver.new stack.region, local
      end
      memoize :resolver

      def diff *args
        Differ.yaml_diff Hash[resolved.sort], Hash[remote.sort], *args<commit_msg>Let region defaults override template defaults<commit_after>require 'memoist'
require 'stacker/differ'
require 'stacker/resolver'
require 'stacker/stack/component'

module Stacker
  class Stack
    class Parameters < Component

      extend Memoist

      # everything required by the template
      def template_definitions
        stack.template.local.fetch 'Parameters', {}
      end

      def region_defaults
        stack.region.defaults.fetch 'parameters', {}
      end

      # template defaults merged with region and stack-specific overrides
      def local
        region_defaults = stack.region.defaults.fetch 'parameters', {}

        template_defaults = Hash[
          template_definitions.select { |_, opts|
            opts.key?('Default')
          }.map { |name, opts|
            [name, opts['Default']]
          }
        ]

        available = template_defaults.merge(
          region_defaults.merge(
            stack.options.fetch 'parameters', {}
          )
        )

        available.slice(*template_definitions.keys)
      end

      def missing
        template_definitions.keys - local.keys
      end

      def remote
        client.parameters
      end
      memoize :remote

      def resolved
        resolver.resolved
      end
      memoize :resolved

      def resolver
        Resolver.new stack.region, local
      end
      memoize :resolver

      def diff *args
        Differ.yaml_diff Hash[resolved.sort], Hash[remote.sort], *args
{'fraction_non_alphanumeric': 0.07665982203969883, 'fraction_numerical': 0.0, 'mean_word_length': 2.029015544041451, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1984039', 'n_tokens_mistral': 767, 'n_tokens_neox': 744, 'n_words': 193}