Class: Travis::Tools::TokenFinder
- Inherits:
-
Object
- Object
- Travis::Tools::TokenFinder
- Defined in:
- lib/travis/tools/token_finder.rb
Overview
This is used when running ‘travis login –auto`
Instance Attribute Summary collapse
-
#explode ⇒ Object
Returns the value of attribute explode.
-
#github ⇒ Object
Returns the value of attribute github.
-
#hub ⇒ Object
Returns the value of attribute hub.
-
#netrc ⇒ Object
Returns the value of attribute netrc.
Class Method Summary collapse
Instance Method Summary collapse
- #find ⇒ Object
- #find_hub ⇒ Object
- #find_netrc ⇒ Object
-
#initialize(options = {}) ⇒ TokenFinder
constructor
A new instance of TokenFinder.
Constructor Details
#initialize(options = {}) ⇒ TokenFinder
Returns a new instance of TokenFinder.
14 15 16 17 18 19 |
# File 'lib/travis/tools/token_finder.rb', line 14 def initialize( = {}) self.netrc = [:netrc] || Netrc.default_path self.hub = [:hub] || ENV['HUB_CONFIG'] || '~/.config/hub' self.github = [:github] || 'github.com' self.explode = [:explode] end |
Instance Attribute Details
#explode ⇒ Object
Returns the value of attribute explode.
8 9 10 |
# File 'lib/travis/tools/token_finder.rb', line 8 def explode @explode end |
#github ⇒ Object
Returns the value of attribute github.
8 9 10 |
# File 'lib/travis/tools/token_finder.rb', line 8 def github @github end |
#hub ⇒ Object
Returns the value of attribute hub.
8 9 10 |
# File 'lib/travis/tools/token_finder.rb', line 8 def hub @hub end |
#netrc ⇒ Object
Returns the value of attribute netrc.
8 9 10 |
# File 'lib/travis/tools/token_finder.rb', line 8 def netrc @netrc end |
Class Method Details
.find(options = {}) ⇒ Object
10 11 12 |
# File 'lib/travis/tools/token_finder.rb', line 10 def self.find( = {}) new().find end |
Instance Method Details
#find ⇒ Object
29 30 31 |
# File 'lib/travis/tools/token_finder.rb', line 29 def find find_netrc || find_hub end |
#find_hub ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/travis/tools/token_finder.rb', line 41 def find_hub return unless File.readable? hub data = YAML.load_file(File.(hub)) data &&= Array(data[github]) data.first['oauth_token'] if data.size == 1 rescue => e raise e if explode end |
#find_netrc ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/travis/tools/token_finder.rb', line 33 def find_netrc return unless File.readable? netrc data = Netrc.read(netrc)[github] data.detect { |e| e.size == 40 } if data rescue => e raise e if explode end |