Class: Shard::Credentials
- Inherits:
-
Struct
- Object
- Struct
- Shard::Credentials
- Defined in:
- lib/shard/credentials.rb
Constant Summary collapse
- GITHUB_API_ENTRY =
# Declarations #
#
"api.github.com"
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.current ⇒ Object
# Class Methods # #.
- .saved? ⇒ Boolean
- .valid? ⇒ Boolean
Instance Method Summary collapse
- #netrc_file ⇒ Object
- #present? ⇒ Boolean
-
#save ⇒ Object
# Instance Methods # #.
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password
6 7 8 |
# File 'lib/shard/credentials.rb', line 6 def password @password end |
#username ⇒ Object
Returns the value of attribute username
6 7 8 |
# File 'lib/shard/credentials.rb', line 6 def username @username end |
Class Method Details
.current ⇒ Object
# Class Methods #
#
22 23 24 25 |
# File 'lib/shard/credentials.rb', line 22 def self.current username, password = Netrc.read[GITHUB_API_ENTRY] new(username, password) end |
.saved? ⇒ Boolean
27 28 29 |
# File 'lib/shard/credentials.rb', line 27 def self.saved? current.present? end |
.valid? ⇒ Boolean
31 32 33 |
# File 'lib/shard/credentials.rb', line 31 def self.valid? Octokit.validate_credentials netrc: true end |
Instance Method Details
#netrc_file ⇒ Object
51 52 53 |
# File 'lib/shard/credentials.rb', line 51 def netrc_file @netrc_file ||= Netrc.read end |
#present? ⇒ Boolean
55 56 57 |
# File 'lib/shard/credentials.rb', line 55 def present? !(username.to_s == '' || password.to_s == '') end |
#save ⇒ Object
# Instance Methods #
#
41 42 43 44 45 46 47 48 49 |
# File 'lib/shard/credentials.rb', line 41 def save if present? netrc_file[GITHUB_API_ENTRY] = username, password else netrc_file.delete GITHUB_API_ENTRY end netrc_file.save end |