'Initialize the environment for installing Ruby packages.  The class is called during the initial
download stage when installing packages, so the value of initial_download will generally be True.
However, the parameter value allows this class to also be used in the second stage of the installation,
although it may never be necessary.  If initial_download is True, the recipe steps will be filtered
and returned and the installation directory (i.e., dir) will be defined and returned.  If we\'re not
in the initial download stage, these actions will not occur, and None values will be returned for them.'

def execute_step(self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder, install_environment, work_dir, current_dir=None, initial_download=False):

    dir = None
    if initial_download:
        filtered_actions = actions[1:]
    env_shell_file_paths = action_dict.get('env_shell_file_paths', None)
    if (env_shell_file_paths is None):
        log.debug('Missing    Ruby    environment,    make    sure    your    specified    Ruby    installation    exists.')
        if initial_download:
            return (tool_dependency, filtered_actions, dir)
        return (tool_dependency, None, None)
    else:
        install_environment.add_env_shell_file_paths(env_shell_file_paths)
    log.debug(('Handling    setup_ruby_environment    for    tool    dependency    %s    with    install_environment.env_shell_file_paths:\n%s' % (str(tool_dependency.name), str(install_environment.env_shell_file_paths))))
    dir = os.path.curdir
    current_dir = os.path.abspath(os.path.join(work_dir, dir))
    with lcd(current_dir):
        with settings(warn_only=True):
            ruby_package_tups = action_dict.get('ruby_package_tups', [])
            for ruby_package_tup_dict in ruby_package_tups:
                ruby_package_tup = ruby_package_tup_dict['package']
                (gem, gem_version, gem_parameters) = ruby_package_tup
                if gem_parameters:
                    gem_parameters = ('--    %s' % gem_parameters)
                else:
                    gem_parameters = ''
                if os.path.isfile(gem):
                    cmd = ('PATH=$PATH:$RUBY_HOME/bin;    export    PATH;    GEM_HOME=$INSTALL_DIR;    export    GEM_HOME;\n                                                                                                                                gem    install    --local    %s    %s' % (gem, gem_parameters))
                elif (gem.find('://') != (-1)):
                    url = gem
                    gem_name = url.split('/')[(-1)]
                    checksums = ruby_package_tup_dict.get('checksums', {})
                    self.url_download(work_dir, gem_name, url, extract=False, checksums=checksums)
                    cmd = ('PATH=$PATH:$RUBY_HOME/bin;    export    PATH;    GEM_HOME=$INSTALL_DIR;    export    GEM_HOME;\n                                                                                                                                gem    install    --local    %s    %s' % (gem_name, gem_parameters))
                elif gem_version:
                    cmd = ('PATH=$PATH:$RUBY_HOME/bin;    export    PATH;    GEM_HOME=$INSTALL_DIR;    export    GEM_HOME;\n                                                                                                                                gem    install    %s    --version    "=%s"    %s' % (gem, gem_version, gem_parameters))
                else:
                    cmd = ('PATH=$PATH:$RUBY_HOME/bin;    export    PATH;    GEM_HOME=$INSTALL_DIR;    export    GEM_HOME;\n                                                                                                                                gem    install    %s    %s' % (gem, gem_parameters))
                cmd = install_environment.build_command(basic_util.evaluate_template(cmd, install_environment))
                return_code = install_environment.handle_command(tool_dependency=tool_dependency, cmd=cmd, return_output=False, job_name=package_name)
                if return_code:
                    if initial_download:
                        return (tool_dependency, filtered_actions, dir)
                    return (tool_dependency, None, None)
            env_file_builder.handle_action_shell_file_paths(action_dict)
            env_file_builder.append_line(name='GEM_PATH', action='prepend_to', value=install_environment.install_dir)
            env_file_builder.append_line(name='PATH', action='prepend_to', value=os.path.join(install_environment.install_dir, 'bin'))
            return_code = env_file_builder.return_code
            if return_code:
                if initial_download:
                    return (tool_dependency, filtered_actions, dir)
                return (tool_dependency, None, None)
    if initial_download:
        return (tool_dependency, filtered_actions, dir)
    return (tool_dependency, None, None)
