class GitPlus::Parsers::Commits::Unsaved::Entry

Parses an unsaved commit entry into a commit object.

Constants

SCISSOR_PATTERN
SUBJECT_INDEX

Attributes

commit[R]
repository[R]
sha[R]

Public Class Methods

call(message) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 17
def self.call message
  new.call message
end
new(sha: SecureRandom.hex(20), commit: Commit.new, repository: Repository.new) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 21
def initialize sha: SecureRandom.hex(20), commit: Commit.new, repository: Repository.new
  @sha = sha
  @commit = commit.dup
  @repository = repository
end

Public Instance Methods

call(message) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 27
def call message
  # TODO: Ensure message remains blank and mimics saved commit behavior with subject
  # only.
  commit.merge!(author_date_relative: "0 seconds ago", message: message, sha: sha)
        .tap { build }
end

Private Instance Methods

body_without_trailers(= commit.body.sub(commit.trailers.join("\n"), "").chomp) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 82
  def body_without_trailers = commit.body.sub(commit.trailers.join("\n"), "").chomp
end
build(= private_methods.grep(/\Astep_/).sort.each { |method| __send__ method }) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 38
          def build = private_methods.grep(/\Astep_/).sort.each { |method| __send__ method }

          def step_a_author_name = commit.author_name = repository.config_get("user.name")

          def step_b_author_email = commit.author_email = repository.config_get("user.email")

          def step_c_subject = commit.subject = commit.message.split("\n").first

          # TODO: Remove leading and trailing empty lines.
          def step_d_body
            commit.message
                  .sub(SCISSOR_PATTERN, "")
                  .split("\n")
                  .drop(SUBJECT_INDEX)
                  .then do |lines|
                    computed_body = lines.join "\n"
                    commit.body = lines.empty? ? computed_body : "#{computed_body}\n"
                  end
          end

          def step_e_trailers
            commit.trailers = repository.trailers_list stdin_data: commit.message
          end

          def step_f_trailers_index
            commit.trailers_index = commit.body.split("\n").index commit.trailers.first
          end

          # TODO: Remove leading and trailing empty lines.
          def step_g_body_lines
            commit.body_lines = body_without_trailers.split("\n")
                                                     .reject { |line| line.start_with? "#" }
                                                     .reverse
                                                     .drop_while(&:empty?).reverse
          end

          # TODO: Remove leading and trailing empty lines.
          def step_h_body_paragraphs
            commit.body_paragraphs = body_without_trailers.split("\n\n")
                                                          .map { |line| line.delete_prefix "\n" }
                                                          .map(&:chomp)
                                                          .reject { |line| line.start_with? "#" }
          end

          def body_without_trailers = commit.body.sub(commit.trailers.join("\n"), "").chomp
        end
      end
    end
  end
end
step_a_author_name(= commit.author_name = repository.config_get("user.name")) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 40
        def step_a_author_name = commit.author_name = repository.config_get("user.name")

        def step_b_author_email = commit.author_email = repository.config_get("user.email")

        def step_c_subject = commit.subject = commit.message.split("\n").first

        # TODO: Remove leading and trailing empty lines.
        def step_d_body
          commit.message
                .sub(SCISSOR_PATTERN, "")
                .split("\n")
                .drop(SUBJECT_INDEX)
                .then do |lines|
                  computed_body = lines.join "\n"
                  commit.body = lines.empty? ? computed_body : "#{computed_body}\n"
                end
        end

        def step_e_trailers
          commit.trailers = repository.trailers_list stdin_data: commit.message
        end

        def step_f_trailers_index
          commit.trailers_index = commit.body.split("\n").index commit.trailers.first
        end

        # TODO: Remove leading and trailing empty lines.
        def step_g_body_lines
          commit.body_lines = body_without_trailers.split("\n")
                                                   .reject { |line| line.start_with? "#" }
                                                   .reverse
                                                   .drop_while(&:empty?).reverse
        end

        # TODO: Remove leading and trailing empty lines.
        def step_h_body_paragraphs
          commit.body_paragraphs = body_without_trailers.split("\n\n")
                                                        .map { |line| line.delete_prefix "\n" }
                                                        .map(&:chomp)
                                                        .reject { |line| line.start_with? "#" }
        end

        def body_without_trailers = commit.body.sub(commit.trailers.join("\n"), "").chomp
      end
    end
  end
end
step_b_author_email(= commit.author_email = repository.config_get("user.email")) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 42
      def step_b_author_email = commit.author_email = repository.config_get("user.email")

      def step_c_subject = commit.subject = commit.message.split("\n").first

      # TODO: Remove leading and trailing empty lines.
      def step_d_body
        commit.message
              .sub(SCISSOR_PATTERN, "")
              .split("\n")
              .drop(SUBJECT_INDEX)
              .then do |lines|
                computed_body = lines.join "\n"
                commit.body = lines.empty? ? computed_body : "#{computed_body}\n"
              end
      end

      def step_e_trailers
        commit.trailers = repository.trailers_list stdin_data: commit.message
      end

      def step_f_trailers_index
        commit.trailers_index = commit.body.split("\n").index commit.trailers.first
      end

      # TODO: Remove leading and trailing empty lines.
      def step_g_body_lines
        commit.body_lines = body_without_trailers.split("\n")
                                                 .reject { |line| line.start_with? "#" }
                                                 .reverse
                                                 .drop_while(&:empty?).reverse
      end

      # TODO: Remove leading and trailing empty lines.
      def step_h_body_paragraphs
        commit.body_paragraphs = body_without_trailers.split("\n\n")
                                                      .map { |line| line.delete_prefix "\n" }
                                                      .map(&:chomp)
                                                      .reject { |line| line.start_with? "#" }
      end

      def body_without_trailers = commit.body.sub(commit.trailers.join("\n"), "").chomp
    end
  end
end
step_c_subject(= commit.subject = commit.message.split("\n").first) click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 44
    def step_c_subject = commit.subject = commit.message.split("\n").first

    # TODO: Remove leading and trailing empty lines.
    def step_d_body
      commit.message
            .sub(SCISSOR_PATTERN, "")
            .split("\n")
            .drop(SUBJECT_INDEX)
            .then do |lines|
              computed_body = lines.join "\n"
              commit.body = lines.empty? ? computed_body : "#{computed_body}\n"
            end
    end

    def step_e_trailers
      commit.trailers = repository.trailers_list stdin_data: commit.message
    end

    def step_f_trailers_index
      commit.trailers_index = commit.body.split("\n").index commit.trailers.first
    end

    # TODO: Remove leading and trailing empty lines.
    def step_g_body_lines
      commit.body_lines = body_without_trailers.split("\n")
                                               .reject { |line| line.start_with? "#" }
                                               .reverse
                                               .drop_while(&:empty?).reverse
    end

    # TODO: Remove leading and trailing empty lines.
    def step_h_body_paragraphs
      commit.body_paragraphs = body_without_trailers.split("\n\n")
                                                    .map { |line| line.delete_prefix "\n" }
                                                    .map(&:chomp)
                                                    .reject { |line| line.start_with? "#" }
    end

    def body_without_trailers = commit.body.sub(commit.trailers.join("\n"), "").chomp
  end
end
step_d_body() click to toggle source

TODO: Remove leading and trailing empty lines.

# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 47
def step_d_body
  commit.message
        .sub(SCISSOR_PATTERN, "")
        .split("\n")
        .drop(SUBJECT_INDEX)
        .then do |lines|
          computed_body = lines.join "\n"
          commit.body = lines.empty? ? computed_body : "#{computed_body}\n"
        end
end
step_e_trailers() click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 58
def step_e_trailers
  commit.trailers = repository.trailers_list stdin_data: commit.message
end
step_f_trailers_index() click to toggle source
# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 62
def step_f_trailers_index
  commit.trailers_index = commit.body.split("\n").index commit.trailers.first
end
step_g_body_lines() click to toggle source

TODO: Remove leading and trailing empty lines.

# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 67
def step_g_body_lines
  commit.body_lines = body_without_trailers.split("\n")
                                           .reject { |line| line.start_with? "#" }
                                           .reverse
                                           .drop_while(&:empty?).reverse
end
step_h_body_paragraphs() click to toggle source

TODO: Remove leading and trailing empty lines.

# File lib/git_plus/parsers/commits/unsaved/entry.rb, line 75
def step_h_body_paragraphs
  commit.body_paragraphs = body_without_trailers.split("\n\n")
                                                .map { |line| line.delete_prefix "\n" }
                                                .map(&:chomp)
                                                .reject { |line| line.start_with? "#" }
end