<commit_before>require "yaml"

module Capistrano
  module FigaroYml
    module Helpers

      def local_figaro_yml(env)
        @local_figaro_yml ||= YAML.load_file(figaro_yml_local_path)
        local_figaro = {}

        @local_figaro_yml.each do |key, value|
          if key == env or !value.is_a?(Hash)
            local_figaro[key] = @local_figaro_yml[key]
          end
        end

        local_figaro
      end

      def figaro_yml_env
        fetch(:figaro_yml_env).to_s
      end

      def figaro_yml_content
        local_figaro_yml(figaro_yml_env).to_yaml
      end

      # error helpers

      def check_git_tracking_error
        puts
        puts "Error - please remove '#{fetch(:figaro_yml_local_path)}' from git:"
        puts
        puts "    $ git rm --cached #{fetch(:figaro_yml_local_path)}"
        puts
        puts "and gitignore it:"
        puts
        puts "    $ echo '#{fetch(:figaro_yml_local_path)}' >> .gitignore"
        puts
      end

      def check_config_present_error
        puts
        puts "Error - '#{figaro_yml_env}' config not present in '#{fetch(:figaro_yml_local_path)}'."
        puts "Please populate it."
        puts
      end

      def check_figaro_file_exists_error
        puts
        puts "Error - '#{fetch(:figaro_yml_local_path)}' file does not exists, and it's required."
        puts
      end

    end
  end
end
<commit_msg>Deploy application.yml using rails_env as the key Since figaro only looks for environment variables corresponding to the application rails environment, if rails_env differs from figaro_yml_env it should always win. This is useful in the scenario where multiple capistrano stages share the same rails_env, but have different environment variables in the local application.yml.<commit_after>require "yaml"

module Capistrano
  module FigaroYml
    module Helpers

      def local_figaro_yml(env)
        @local_figaro_yml ||= YAML.load_file(figaro_yml_local_path)
        local_figaro = {}
        deployment_env = fetch(:rails_env, env)

        @local_figaro_yml.each do |key, value|
          if key == env or !value.is_a?(Hash)
            local_figaro[deployment_env] = @local_figaro_yml[key]
          end
        end

        local_figaro
      end

      def figaro_yml_env
        fetch(:figaro_yml_env).to_s
      end

      def figaro_yml_content
        local_figaro_yml(figaro_yml_env).to_yaml
      end

      # error helpers

      def check_git_tracking_error
        puts
        puts "Error - please remove '#{fetch(:figaro_yml_local_path)}' from git:"
        puts
        puts "    $ git rm --cached #{fetch(:figaro_yml_local_path)}"
        puts
        puts "and gitignore it:"
        puts
        puts "    $ echo '#{fetch(:figaro_yml_local_path)}' >> .gitignore"
        puts
      end

      def check_config_present_error
        puts
        puts "Error - '#{figaro_yml_env}' config not present in '#{fetch(:figaro_yml_local_path)}'."
        puts "Please populate it."
        puts
      end

      def check_figaro_file_exists_error
        puts
        puts "Error - '#{fetch(:figaro_yml_local_path)}' file does not exists, and it's required."
        puts
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.076347771891555, 'fraction_numerical': 0.0, 'mean_word_length': 2.302469135802469, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4921641', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1005, 'n_words': 256}