Sha256: 5af89e16e397c9b155eac5c6d3f19d971b29b625c362437da60318ad7d3c42df

Contents?: true

Size: 1.86 KB

Versions: 303

Compression:

Stored size: 1.86 KB

Contents

require_relative "create_file"

class Bundler::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)
      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?
        source = File.expand_path(render, File.dirname(destination))
        exists? && File.identical?(source, destination)
      end

      def invoke!
        invoke_with_conflict_check do
          require "fileutils"
          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

303 entries across 303 versions & 6 rubygems

Version Path
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb