Sha256: c78405d7dc19565fc1694704b0c5a8e19984417cca27948ae9eb8f27cc7f0078

Contents?: true

Size: 1.51 KB

Versions: 21

Compression:

Stored size: 1.51 KB

Contents

module ReactOnRails
  module TaskHelpers
    # Returns the root folder of the react_on_rails gem
    def gem_root
      File.expand_path("../../.", __FILE__)
    end

    # Returns the folder where examples are located
    def examples_dir
      File.join(gem_root, "gen-examples", "examples")
    end

    def dummy_app_dir
      File.join(gem_root, "spec/dummy")
    end

    # Executes a string or an array of strings in a shell in the given directory
    def sh_in_dir(dir, shell_commands)
      shell_commands = [shell_commands] if shell_commands.is_a?(String)
      shell_commands.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) }
    end

    def bundle_install_in(dir)
      sh_in_dir(dir, "bundle install")
    end

    def bundle_install_in_no_turbolinks(dir)
      sh_in_dir(dir, "DISABLE_TURBOLINKS=TRUE bundle install")
    end

    def bundle_install_with_turbolinks_2_in(dir)
      sh_in_dir(dir, "ENABLE_TURBOLINKS_2=TRUE BUNDLE_GEMFILE=#{dir}/Gemfile bundle install")
    end

    # Runs bundle exec using that directory's Gemfile
    def bundle_exec(dir: nil, args: nil, env_vars: "")
      sh_in_dir(dir, "#{env_vars} #{args}")
    end

    def generators_source_dir
      File.join(gem_root, "lib/generators/react_on_rails")
    end

    def symbolize_keys(hash)
      hash.each_with_object({}) do |(key, value), new_hash|
        new_key = key.is_a?(String) ? key.to_sym : key
        new_value = value.is_a?(Hash) ? symbolize_keys(value) : value
        new_hash[new_key] = new_value
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
react_on_rails-8.0.1 rakelib/task_helpers.rb
react_on_rails-8.0.0 rakelib/task_helpers.rb
react_on_rails-8.0.0.beta.3 rakelib/task_helpers.rb
react_on_rails-8.0.0.beta.2 rakelib/task_helpers.rb
react_on_rails-8.0.0.beta.1 rakelib/task_helpers.rb
react_on_rails-7.1.0.beta.3 rakelib/task_helpers.rb
react_on_rails-7.0.4 rakelib/task_helpers.rb
react_on_rails-7.1.0.beta.2 rakelib/task_helpers.rb
react_on_rails-7.0.3 rakelib/task_helpers.rb
react_on_rails-7.1.0.beta.1 rakelib/task_helpers.rb
react_on_rails-7.0.2 rakelib/task_helpers.rb
react_on_rails-7.0.1 rakelib/task_helpers.rb
react_on_rails-7.0.0 rakelib/task_helpers.rb
react_on_rails-6.10.1 rakelib/task_helpers.rb
react_on_rails-6.10.0 rakelib/task_helpers.rb
react_on_rails-6.9.3 rakelib/task_helpers.rb
react_on_rails-6.9.2 rakelib/task_helpers.rb
react_on_rails-6.9.1 rakelib/task_helpers.rb
react_on_rails-6.9.0 rakelib/task_helpers.rb
react_on_rails-6.8.2 rakelib/task_helpers.rb