<commit_before>class Jeweler
  module Commands
    module Version
      class Base

        attr_accessor :repo, :version_helper, :gemspec, :commit

        def run
          update_version

          self.version_helper.write
          self.gemspec.version = self.version_helper.to_s

          commit_version if self.repo && self.commit
        end

        def update_version
          raise "Subclasses should implement this"
        end

        def commit_version
          if self.repo
            self.repo.add(version_helper.path)
            self.repo.commit("Version bump to #{self.version_helper.to_s}")
          end
        end


        def self.build_for(jeweler)
          command = new
          command.repo = jeweler.repo
          command.version_helper = jeweler.version_helper
          command.gemspec = jeweler.gemspec
          command.commit = jeweler.commit

          command
        end
      end
    end
  end
end<commit_msg>make versioning work when gem directory is not at top level<commit_after>require 'pathname'

class Jeweler
  module Commands
    module Version
      class Base

        attr_accessor :repo, :version_helper, :gemspec, :commit, :base_dir

        def run
          update_version

          self.version_helper.write
          self.gemspec.version = self.version_helper.to_s

          commit_version if self.repo && self.commit
        end

        def update_version
          raise "Subclasses should implement this"
        end

        def commit_version
          if self.repo
            self.repo.add(working_subdir.join(version_helper.path))
            self.repo.commit("Version bump to #{self.version_helper.to_s}")
          end
        end

        def working_subdir
          return @working_subdir if @working_subdir
          cwd = base_dir_path
          @working_subdir = cwd.relative_path_from(Pathname.new(repo.dir.path))
          @working_subdir
        end

        def base_dir_path
          Pathname.new(base_dir).realpath
        end


        def self.build_for(jeweler)
          command = new
          command.repo = jeweler.repo
          command.version_helper = jeweler.version_helper
          command.gemspec = jeweler.gemspec
          command.commit = jeweler.commit
          command.base_dir = jeweler.base_dir

          command
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.05919661733615222, 'fraction_numerical': 0.0, 'mean_word_length': 1.8133174791914388, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4135118', 'n_tokens_mistral': 658, 'n_tokens_neox': 639, 'n_words': 152}