Sha256: 6fe9a8daf4268312bcb0da359022af3a62cbb1b3dd864c780b797c6719a60cb2

Contents?: true

Size: 1.76 KB

Versions: 190

Compression:

Stored size: 1.76 KB

Contents

require "thor/actions/create_file"

class Thor
  module Actions
    # Create a new file relative to the destination root from the given source.
    #
    # ==== Parameters
    # destination<String>:: the relative path to the destination root.
    # source<String|NilClass>:: the relative path to the source root.
    # config<Hash>:: give :verbose => false to not log the status.
    #   :: give :symbolic => false for hard link.
    #
    # ==== Examples
    #
    #   create_link "config/apache.conf", "/etc/apache.conf"
    #
    def create_link(destination, *args, &block)
      config = args.last.is_a?(Hash) ? args.pop : {}
      source = args.first
      action CreateLink.new(self, destination, source, config)
    end
    alias_method :add_link, :create_link

    # CreateLink is a subset of CreateFile, which instead of taking a block of
    # data, just takes a source string from the user.
    #
    class CreateLink < CreateFile #:nodoc:
      attr_reader :data

      # Checks if the content of the file at the destination is identical to the rendered result.
      #
      # ==== Returns
      # Boolean:: true if it is identical, false otherwise.
      #
      def identical?
        exists? && File.identical?(render, destination)
      end

      def invoke!
        invoke_with_conflict_check do
          FileUtils.mkdir_p(File.dirname(destination))
          # Create a symlink by default
          config[:symbolic] = true if config[:symbolic].nil?
          File.unlink(destination) if exists?
          if config[:symbolic]
            File.symlink(render, destination)
          else
            File.link(render, destination)
          end
        end
        given_destination
      end

      def exists?
        super || File.symlink?(destination)
      end
    end
  end
end

Version data entries

190 entries across 186 versions & 22 rubygems

Version Path
honeybadger-5.24.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.23.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.22.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.21.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.20.1 vendor/cli/thor/actions/create_link.rb
honeybadger-5.20.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.19.2 vendor/cli/thor/actions/create_link.rb
honeybadger-5.19.1 vendor/cli/thor/actions/create_link.rb
honeybadger-5.19.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.18.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.17.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.16.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.6 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.5 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.4 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.3 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.2 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.1 vendor/cli/thor/actions/create_link.rb
honeybadger-5.15.0 vendor/cli/thor/actions/create_link.rb
honeybadger-5.14.2 vendor/cli/thor/actions/create_link.rb