env_branch 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +83 -7
- data/changelog.md +6 -0
- data/env_branch.gemspec +2 -2
- data/lib/env_branch/base.rb +31 -0
- data/lib/env_branch/test_helper.rb +34 -0
- data/lib/env_branch/version.rb +1 -1
- data/lib/env_branch.rb +21 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4058b3d53fa644c1bcb92445ec4b36e399e1e81b
|
|
4
|
+
data.tar.gz: 51553be2677fd4ab107c0bcdb5898ff1f33a3b46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9bc77f5838ab92d6ff7172587b5aaedf5e304a4a9f3062f7aa7aad4cef6f7e43347dd116254c50a366ada75288f624418b070ec64046e533f83a96d01d60a05
|
|
7
|
+
data.tar.gz: 70703f2a07317362253dc88d26b1de3160354e38806dd8428db391b4c6f65460ef5cbb836b9b46f99dffd46268d03409812eeeb5358d4fde2292abd1a42e1f32
|
data/README.md
CHANGED
|
@@ -1,8 +1,78 @@
|
|
|
1
1
|
# EnvBranch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![Gem version][gem-image]][gem-url] [![Travis-CI Status][travis-image]][travis-url] [![yard docs][docs-image]][docs-url]
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Get BRANCH_NAME from environment variables.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
require 'env_branch'
|
|
12
|
+
|
|
13
|
+
env_branch = EnvBranch.new
|
|
14
|
+
env_branch.branch? #=> true
|
|
15
|
+
env_branch.branch_name #=> 'your-branch-name'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### User defined block
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
require 'env_branch'
|
|
22
|
+
|
|
23
|
+
env_branch =
|
|
24
|
+
EnvBranch.new do
|
|
25
|
+
if ENV['USER_DEFINED_BRANCH'] &&
|
|
26
|
+
!ENV['USER_DEFINED_BRANCH'].empty?
|
|
27
|
+
ENV['USER_DEFINED_BRANCH']
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
env_branch.branch? #=> true
|
|
32
|
+
env_branch.branch_name #=> 'your-branch-name'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## API
|
|
37
|
+
|
|
38
|
+
### EnvBranch.new -> Base
|
|
39
|
+
|
|
40
|
+
### EnvBranch.new(&block) -> Base
|
|
41
|
+
|
|
42
|
+
#### block
|
|
43
|
+
|
|
44
|
+
*optional*
|
|
45
|
+
|
|
46
|
+
Type: `block`
|
|
47
|
+
|
|
48
|
+
User defined block for getting `branch name`.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Base#branch_name -> String | nil
|
|
52
|
+
|
|
53
|
+
Return branch name or nil.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Base#branch? -> boolean
|
|
57
|
+
|
|
58
|
+
Return true if this has branch name.
|
|
59
|
+
|
|
60
|
+
And more *[details][docs-url]*.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## Supported services / applications
|
|
64
|
+
|
|
65
|
+
* Travis-ci
|
|
66
|
+
* `ENV['TRAVIS_BRANCH']`
|
|
67
|
+
* [Environment Variables - Travis CI](http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)
|
|
68
|
+
* CircleCI
|
|
69
|
+
* `ENV['CIRCLE_BRANCH']`
|
|
70
|
+
* [Environment variables - CircleCI](https://circleci.com/docs/environment-variables#build-details)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Changelog
|
|
74
|
+
|
|
75
|
+
[changelog.md](./changelog.md).
|
|
6
76
|
|
|
7
77
|
## Installation
|
|
8
78
|
|
|
@@ -20,22 +90,28 @@ Or install it yourself as:
|
|
|
20
90
|
|
|
21
91
|
$ gem install env_branch
|
|
22
92
|
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
TODO: Write usage instructions here
|
|
26
93
|
|
|
27
94
|
## Development
|
|
28
95
|
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
|
96
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
97
|
|
|
31
98
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
99
|
|
|
100
|
+
|
|
33
101
|
## Contributing
|
|
34
102
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/packsaddle/ruby-env_branch. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
|
36
104
|
|
|
37
105
|
|
|
38
106
|
## License
|
|
39
107
|
|
|
108
|
+
© [sanemat](http://sane.jp)
|
|
109
|
+
|
|
40
110
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
41
111
|
|
|
112
|
+
[travis-url]: https://travis-ci.org/packsaddle/ruby-env_branch
|
|
113
|
+
[travis-image]: https://img.shields.io/travis/packsaddle/ruby-env_branch/master.svg?style=flat-square&label=build%20%28linux%29
|
|
114
|
+
[gem-url]: https://rubygems.org/gems/env_branch
|
|
115
|
+
[gem-image]: http://img.shields.io/gem/v/env_branch.svg?style=flat-square
|
|
116
|
+
[docs-url]: http://www.rubydoc.info/gems/env_branch
|
|
117
|
+
[docs-image]: https://img.shields.io/badge/yard-docs-blue.svg?style=flat-square
|
data/changelog.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
<a name="0.2.1"></a>
|
|
2
|
+
## [0.2.1](https://github.com/packsaddle/ruby-env_branch/compare/v0.2.0...v0.2.1) (2015-09-28)
|
|
3
|
+
|
|
4
|
+
* Improve document.
|
|
5
|
+
|
|
6
|
+
|
|
1
7
|
<a name="0.2.0"></a>
|
|
2
8
|
# [0.2.0](https://github.com/packsaddle/ruby-env_branch/compare/v0.1.1...v0.2.0) (2015-09-28)
|
|
3
9
|
|
data/env_branch.gemspec
CHANGED
|
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.email = ['o.gata.ken@gmail.com']
|
|
11
11
|
|
|
12
12
|
spec.summary =
|
|
13
|
-
'Get
|
|
13
|
+
'Get BRANCH_NAME from environment variables.'
|
|
14
14
|
spec.description =
|
|
15
|
-
'Get
|
|
15
|
+
'Get BRANCH_NAME from environment variables.'
|
|
16
16
|
spec.homepage = 'https://github.com/packsaddle/ruby-env_branch'
|
|
17
17
|
spec.license = 'MIT'
|
|
18
18
|
|
data/lib/env_branch/base.rb
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
module EnvBranch
|
|
2
|
+
# Branch information object from environment variable
|
|
2
3
|
class Base
|
|
3
4
|
attr_reader :branch_name
|
|
5
|
+
# @!attribute [r] branch_name
|
|
6
|
+
# @return [String, nil] branch name or nil
|
|
4
7
|
|
|
8
|
+
# Build branch information object from environment variables
|
|
9
|
+
#
|
|
10
|
+
# @overload initialize
|
|
11
|
+
# @example without user defined block
|
|
12
|
+
# env_branch = EnvBranch::Base.new
|
|
13
|
+
#
|
|
14
|
+
# @return [Base] Branch information object
|
|
15
|
+
#
|
|
16
|
+
# @overload initialize(&block)
|
|
17
|
+
# @example with user defined block
|
|
18
|
+
# env_branch =
|
|
19
|
+
# EnvBranch::Base.new do
|
|
20
|
+
# if ENV['USER_DEFINED_BRANCH'] &&
|
|
21
|
+
# !ENV['USER_DEFINED_BRANCH'].empty?
|
|
22
|
+
# ENV['USER_DEFINED_BRANCH']
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# @yield user defined block
|
|
27
|
+
# @return [Base] Branch information object
|
|
5
28
|
def initialize(&block)
|
|
6
29
|
@branch_name =
|
|
7
30
|
if block_given?
|
|
@@ -11,11 +34,18 @@ module EnvBranch
|
|
|
11
34
|
end
|
|
12
35
|
end
|
|
13
36
|
|
|
37
|
+
# Fetch branch name from environment variables
|
|
38
|
+
#
|
|
14
39
|
# travis-ci.org:
|
|
15
40
|
# ENV['TRAVIS_BRANCH']
|
|
16
41
|
# circleci.com:
|
|
17
42
|
# ENV['CIRCLE_BRANCH']
|
|
18
43
|
#
|
|
44
|
+
# @return [String, nil] branch name or nil
|
|
45
|
+
#
|
|
46
|
+
# @see TestHelper.stash_env_branch
|
|
47
|
+
# @see TestHelper.restore_env_branch
|
|
48
|
+
#
|
|
19
49
|
# @see http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|
|
20
50
|
# Environment Variables - Travis CI
|
|
21
51
|
# @see https://circleci.com/docs/environment-variables#build-details
|
|
@@ -28,6 +58,7 @@ module EnvBranch
|
|
|
28
58
|
end
|
|
29
59
|
end
|
|
30
60
|
|
|
61
|
+
# @return [Boolean] true if this has branch name
|
|
31
62
|
def branch?
|
|
32
63
|
!branch_name.nil?
|
|
33
64
|
end
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
module EnvBranch
|
|
2
|
+
# Test helper for branch with environment variables
|
|
2
3
|
module TestHelper
|
|
3
4
|
module_function
|
|
4
5
|
|
|
6
|
+
# Stash original environment variables for branch.
|
|
7
|
+
# And delete for testing.
|
|
8
|
+
#
|
|
9
|
+
# @example with test-unit
|
|
10
|
+
# require 'env_branch/test_helper'
|
|
11
|
+
#
|
|
12
|
+
# class TestExample < Test::Unit::TestCase
|
|
13
|
+
# extend ::EnvBranch::TestHelper
|
|
14
|
+
#
|
|
15
|
+
# def self.startup
|
|
16
|
+
# stash_env_branch
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# @return [void]
|
|
21
|
+
#
|
|
22
|
+
# @see Base#fetch_branch_name
|
|
5
23
|
def stash_env_branch
|
|
6
24
|
@original_travis_branch = ENV['TRAVIS_BRANCH']
|
|
7
25
|
@original_circle_branch = ENV['CIRCLE_BRANCH']
|
|
@@ -9,6 +27,22 @@ module EnvBranch
|
|
|
9
27
|
ENV.delete 'CIRCLE_BRANCH'
|
|
10
28
|
end
|
|
11
29
|
|
|
30
|
+
# Restore original environment variables for branch.
|
|
31
|
+
#
|
|
32
|
+
# @example with test-unit
|
|
33
|
+
# require 'env_branch/test_helper'
|
|
34
|
+
#
|
|
35
|
+
# class TestExample < Test::Unit::TestCase
|
|
36
|
+
# extend ::EnvBranch::TestHelper
|
|
37
|
+
#
|
|
38
|
+
# def self.shutdown
|
|
39
|
+
# restore_env_branch
|
|
40
|
+
# end
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# @return [void]
|
|
44
|
+
#
|
|
45
|
+
# @see Base#fetch_branch_name
|
|
12
46
|
def restore_env_branch
|
|
13
47
|
ENV['TRAVIS_BRANCH'] = @original_travis_branch
|
|
14
48
|
ENV['CIRCLE_BRANCH'] = @original_circle_branch
|
data/lib/env_branch/version.rb
CHANGED
data/lib/env_branch.rb
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
require 'env_branch/base'
|
|
2
2
|
require 'env_branch/version'
|
|
3
3
|
|
|
4
|
+
# Build branch information from environment variables
|
|
4
5
|
module EnvBranch
|
|
6
|
+
# Build branch information object from environment variables
|
|
7
|
+
#
|
|
8
|
+
# @overload self.new
|
|
9
|
+
# @example without user defined block
|
|
10
|
+
# env_branch = EnvBranch.new
|
|
11
|
+
#
|
|
12
|
+
# @return [Base] Branch information object
|
|
13
|
+
#
|
|
14
|
+
# @overload self.new(&block)
|
|
15
|
+
# @example with user defined block
|
|
16
|
+
# env_branch =
|
|
17
|
+
# EnvBranch.new do
|
|
18
|
+
# if ENV['USER_DEFINED_BRANCH'] &&
|
|
19
|
+
# !ENV['USER_DEFINED_BRANCH'].empty?
|
|
20
|
+
# ENV['USER_DEFINED_BRANCH']
|
|
21
|
+
# end
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# @yield user defined block
|
|
25
|
+
# @return [Base] Branch information object
|
|
5
26
|
def self.new(&block)
|
|
6
27
|
Base.new(&block)
|
|
7
28
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: env_branch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sanemat
|
|
@@ -52,7 +52,7 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
-
description: Get
|
|
55
|
+
description: Get BRANCH_NAME from environment variables.
|
|
56
56
|
email:
|
|
57
57
|
- o.gata.ken@gmail.com
|
|
58
58
|
executables: []
|
|
@@ -104,6 +104,6 @@ rubyforge_project:
|
|
|
104
104
|
rubygems_version: 2.4.5
|
|
105
105
|
signing_key:
|
|
106
106
|
specification_version: 4
|
|
107
|
-
summary: Get
|
|
107
|
+
summary: Get BRANCH_NAME from environment variables.
|
|
108
108
|
test_files: []
|
|
109
109
|
has_rdoc:
|