Sha256: 76755245a463a37680c093bc9db427ffb9f7f429c9d2bc6d07cbb771ed3a3438

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Mercurial

  #
  # This class represents a factory for {Mercurial::Tag Tag} instances.
  #
  class TagFactory
    include Mercurial::Helper
    
    # Instance of {Mercurial::Repository Repository}.
    attr_reader :repository
    
    def initialize(repository)
      @repository = repository
    end
    
    # Return an array of {Mercurial::Tag Tag} instances for all tags in the repository.
    #
    # == Example:
    #  repository.tags.all 
    #
    def all(cmd_options={})
      hg_to_array("tags", {}, cmd_options) do |line|
        build(line)
      end
    end
    
    # Return a {Mercurial::Tag Tag} instance for a tag with a specified name.
    #
    # == Example:
    #  repository.tags.by_name('tagname')
    #
    def by_name(name)
      all.find do |b|
        b.name == name
      end
    end
    
  private
  
    def build(data)
      name, hash_id = *data.scan(/([\w-]+)\s+\d+:(\w+)\s*/).first
      return if name == 'tip'
      Mercurial::Tag.new(repository, name, hash_id)
    end

  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mercurial-ruby-0.7.0 lib/mercurial-ruby/factories/tag_factory.rb
mercurial-ruby-0.6.1 lib/mercurial-ruby/factories/tag_factory.rb
mercurial-ruby-0.6.0 lib/mercurial-ruby/factories/tag_factory.rb