<commit_before>require 'itamae'

module Itamae
  module Resource
    class Link < Base
      define_attribute :action, default: :create
      define_attribute :link, type: String, default_name: true
      define_attribute :to, type: String, required: true

      def create_action
        if ! run_specinfra(:check_file_is_linked_to, link, to)
          run_specinfra(:link_file_to, link, to)
        end
      end
    end
  end
end<commit_msg>Show diff of link resource.<commit_after>require 'itamae'

module Itamae
  module Resource
    class Link < Base
      define_attribute :action, default: :create
      define_attribute :link, type: String, default_name: true
      define_attribute :to, type: String, required: true

      def pre_action
        case action
        when :create
          @attributes[:exist?] = true
        end
      end

      def set_current_attributes
        @current_attributes[:exist?] = (run_command(["test", "-L", link]).exit_status == 0)

        if @current_attributes[:exist?]
          @current_attributes[:to] = run_command(["readlink", "-f", link]).stdout.strip
        end
      end

      def create_action
        unless run_specinfra(:check_file_is_linked_to, link, to)
          run_specinfra(:link_file_to, link, to)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08742331288343558, 'fraction_numerical': 0.0007668711656441718, 'mean_word_length': 2.6864406779661016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6013719', 'n_tokens_mistral': 394, 'n_tokens_neox': 383, 'n_words': 106}