Flowdock
method

install

Importance_0
Ruby latest stable (v2_5_5) - 0 notes - Class: Runner
  • 1_8_6_287
  • 1_8_7_72
  • 1_8_7_330
  • 1_9_1_378
  • 1_9_2_180
  • 1_9_3_125
  • 1_9_3_392
  • 2_1_10
  • 2_2_9
  • 2_4_6
  • 2_5_5
  • 2_6_3 (0)
  • What's this?

Method not available on this version

This method is only available on newer versions. The first available version of the method is shown here.

install(name) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/bundler/vendor/thor/lib/thor/runner.rb, line 47
  def install(name) # rubocop:disable MethodLength
    initialize_thorfiles

    # If a directory name is provided as the argument, look for a 'main.thor'
    # command in said directory.
    begin
      if File.directory?(File.expand_path(name))
        base = File.join(name, "main.thor")
        package = :directory
        contents = open(base, &:read)
      else
        base = name
        package = :file
        contents = open(name, &:read)
      end
    rescue OpenURI::HTTPError
      raise Error, "Error opening URI '#{name}'"
    rescue Errno::ENOENT
      raise Error, "Error opening file '#{name}'"
    end

    say "Your Bundler::Thorfile contains:"
    say contents

    unless options["force"]
      return false if no?("Do you wish to continue [y/N]?")
    end

    as = options["as"] || begin
      first_line = contents.split("\n")[0]
      (match = first_line.match(/\s*#\s*module:\s*([^\n]*)/)) ? match[1].strip : nil
    end

    unless as
      basename = File.basename(name)
      as = ask("Please specify a name for #{name} in the system repository [#{basename}]:")
      as = basename if as.empty?
    end

    location = if options[:relative] || name =~ %{^https?://}
      name
    else
      File.expand_path(name)
    end

    thor_yaml[as] = {
      :filename   => Digest(:MD5).hexdigest(name + as),
      :location   => location,
      :namespaces => Bundler::Thor::Util.namespaces_in_content(contents, base)
    }

    save_yaml(thor_yaml)
    say "Storing thor file in your system repository"
    destination = File.join(thor_root, thor_yaml[as][:filename])

    if package == :file
      File.open(destination, "w") { |f| f.puts contents }
    else
      require "fileutils"
      FileUtils.cp_r(name, destination)
    end

    thor_yaml[as][:filename] # Indicate success
  end
Register or log in to add new notes.