Skip to content

Commit 1311414

Browse files
authored
Add deprecation mechanism (introduces runtime dependency on ActiveSupport) (#645)
* Add deprecation mechanism (introduces runtime dependency on ActiveSupport) Signed-off-by: James Couball <jcouball@yahoo.com> * Disable YARD doc generation when using TruffleRuby Signed-off-by: James Couball <jcouball@yahoo.com> --------- Signed-off-by: James Couball <jcouball@yahoo.com>
1 parent 50b8123 commit 1311414

File tree

6 files changed

+91
-26
lines changed

6 files changed

+91
-26
lines changed

README.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,73 @@
33
# @title README
44
-->
55

6-
# The Git Gem
6+
# The `git` Gem
77

8-
The Git Gem provides an API that can be used to create, read, and manipulate
8+
[![Gem Version](https://badge.fury.io/rb/git.svg)](https://badge.fury.io/rb/git)
9+
[![Change Log](https://img.shields.io/badge/change%20log-Latest-green)](https://rubydoc.info/gems/git/file/CHANGELOG.md)
10+
[![Build Status](https://github.com/ruby-git/ruby-git/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/ruby-git/ruby-git/actions/workflows/continuous_integration.yml)
11+
[![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
12+
[![Source Code](https://img.shields.io/badge/source-GitHub-green)](https://github.com/ruby-git/ruby-git)
13+
[![Documentation](https://img.shields.io/badge/documentation-Latest-green)](https://rubydoc.info/gems/git)
14+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ruby-git/ruby-git/blob/master/LICENSE)
15+
16+
The git Gem provides an API that can be used to create, read, and manipulate
917
Git repositories by wrapping system calls to the `git` binary. The API can be
1018
used for working with Git in complex interactions including branching and
1119
merging, object inspection and manipulation, history, patch generation and
1220
more.
1321

14-
## Homepage
22+
## Basic Usage
1523

16-
The project source code is at:
24+
Get started by obtaining a repository object by:
1725

18-
http://github.com/ruby-git/ruby-git
26+
* Opening an existing working copy with [Git.open](https://rubydoc.info/gems/git/Git#open-class_method)
27+
* Initializing a new repository with [Git.init](https://rubydoc.info/gems/git/Git#init-class_method)
28+
* Cloning a repository with [Git.clone](https://rubydoc.info/gems/git/Git#clone-class_method)
1929

20-
## Documentation
30+
Methods that can be called on a repository object are documented in [Git::Base](https://rubydoc.info/gems/git/Git/Base)
2131

22-
Detailed documentation can be found at:
32+
## Install
2333

24-
https://rubydoc.info/gems/git/Git.html
34+
You can install the `git` gem with the following command:
2535

26-
Get started by obtaining a repository object by:
27-
28-
* opening an existing working copy with [Git.open](https://rubydoc.info/gems/git/Git#open-class_method)
29-
* initializing a new repository with [Git.init](https://rubydoc.info/gems/git/Git#init-class_method)
30-
* cloning a repository with [Git.clone](https://rubydoc.info/gems/git/Git#clone-class_method)
36+
```shell
37+
gem install git
38+
```
3139

32-
Methods that can be called on a repository object are documented in [Git::Base](https://rubydoc.info/gems/git/Git/Base)
40+
## Deprecation Warnings
3341

34-
## Install
42+
Deprecation warnings are managed with the `Git.deprecation` attribute.
3543

36-
You can install Ruby/Git like this:
44+
Use this object to define deprecations in the source code:
3745

46+
```ruby
47+
Git.deprecation.deprecate_methods(Git::Branch, stashes: 'use Git::Base#stash_list instead')
3848
```
39-
sudo gem install git
49+
50+
The default action when using deprecated items (methods, classes, etc.) is to output
51+
a **DEPRECATION WARNING** to `$stderr` like the following:
52+
53+
```text
54+
DEPRECATION WARNING: stashes is deprecated and will be removed from git 2.0.0 (use Git::Base.stash_list instead)
4055
```
4156

42-
## Code Status
57+
The action taken when a deprecated item is used is defined by setting the behavior
58+
on the deprecation object:
59+
60+
```ruby
61+
# Log all deprecation warnings to $stderr (the default)
62+
Git.deprecation = :stderr
63+
64+
# Raise an ActiveSupport::DeprecationException
65+
Git.deprecation = :raise
66+
67+
# Do nothing
68+
Git.deprecation = :silence
69+
```
4370

44-
* [![Build Status](https://github.com/ruby-git/ruby-git/workflows/CI/badge.svg?branch=master)](https://github.com/ruby-git/ruby-git/actions?query=workflow%3ACI)
45-
* [![Code Climate](https://codeclimate.com/github/ruby-git/ruby-git.png)](https://codeclimate.com/github/ruby-git/ruby-git)
46-
* [![Gem Version](https://badge.fury.io/rb/git.svg)](https://badge.fury.io/rb/git)
71+
See [ActiveSupport::Deprecation](https://api.rubyonrails.org/classes/ActiveSupport/Deprecation.html)
72+
for more details on how to use deprecations.
4773

4874
## Major Objects
4975

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ task :test do
1818
end
1919
default_tasks << :test
2020

21-
unless RUBY_PLATFORM == 'java'
21+
unless RUBY_PLATFORM == 'java' || RUBY_ENGINE == 'truffleruby'
2222
#
2323
# YARD documentation for this project can NOT be built with JRuby.
2424
# This project uses the redcarpet gem which can not be installed on JRuby.

git.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
2727
s.requirements = ['git 1.6.0.0, or greater']
2828

29+
s.add_runtime_dependency 'activesupport', '>= 4.0.0'
2930
s.add_runtime_dependency 'addressable', '~> 2.8'
3031
s.add_runtime_dependency 'rchardet', '~> 1.8'
3132

lib/git.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
# Add the directory containing this file to the start of the load path if it
2-
# isn't there already.
3-
$:.unshift(File.dirname(__FILE__)) unless
4-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1+
require 'active_support/deprecation'
2+
3+
module Git
4+
# An object used to manage deprecations
5+
#
6+
# A ActiveSupport::Deprecation object used to manage the deprecations scheduled
7+
# to be removed in the next major release of the `git`` gem.
8+
#
9+
# @example Deprecate a method
10+
# Git.deprecation.deprecate_methods(Git::Branch, stashes: 'use Git::Base#stash_list instead')
11+
#
12+
# @example Set the deprecation behavior
13+
# # Log all deprecation warnings to $stderr (the default)
14+
# Git.deprecation.behavior = :stderr
15+
#
16+
# # Raise an ActiveSupport::DeprecationException
17+
# Git.deprecation.behavior = :raise
18+
#
19+
# # Do nothing
20+
# Git.deprecation.behavior = :raise
21+
#
22+
# @see https://api.rubyonrails.org/classes/ActiveSupport/Deprecation.html ActiveSupport::Deprecation
23+
#
24+
# @return [ActiveSupport::Deprecation]
25+
#
26+
def self.deprecation
27+
@deprecation ||= ActiveSupport::Deprecation.new('2.0.0', 'git')
28+
end
29+
end
530

631
require 'git/author'
732
require 'git/base'

tests/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
require "git"
77

8+
Git.deprecation.behavior = :silence
9+
810
class Test::Unit::TestCase
911

1012
TEST_ROOT = File.expand_path(__dir__)

tests/units/test_git_deprecation.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'test_helper'
2+
3+
class TestGitDeprecation < Test::Unit::TestCase
4+
test 'Git.deprecation should return an ActiveSupport::Deprecation' do
5+
assert(Git.deprecation.is_a?(ActiveSupport::Deprecation))
6+
end
7+
8+
test 'Calling Git.deprecation more than once should return the same object' do
9+
assert_equal(Git.deprecation.object_id, Git.deprecation.object_id)
10+
end
11+
end

0 commit comments

Comments
 (0)