Sha256: 15d82e4d8e4018c3b6a07b8a040faceb68b18a2a7434a4ed5fd2c35d484d5974

Contents?: true

Size: 1.66 KB

Versions: 129

Compression:

Stored size: 1.66 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 :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
          File.unlink(destination) if exists?
          if config[:symbolic]
            File.symlink(render, destination)
          else
            File.link(render, destination)
          end
        end
        given_destination
      end

    end
  end
end

Version data entries

129 entries across 124 versions & 16 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.7.5 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.7.4 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.7.3 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/thor-0.14.6/lib/thor/actions/create_link.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/thor-0.14.6/lib/thor/actions/create_link.rb
wijet-thor-0.14.10 lib/thor/actions/create_link.rb
classiccms-0.7.2 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.7.1 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.7.0 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
wijet-thor-0.14.9 lib/thor/actions/create_link.rb
classiccms-0.6.9 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.8 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.7 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.6 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.5 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.4 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.3 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.2 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb
classiccms-0.6.1 vendor/bundle/gems/thor-0.14.6/lib/thor/actions/create_link.rb