Class: Hapyrus::Credentials
- Inherits:
-
Object
- Object
- Hapyrus::Credentials
- Includes:
- Helpers
- Defined in:
- lib/hapyrus/credentials.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
-
#initialize(user = nil, password = nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #write_credentials ⇒ Object
Methods included from Helpers
home_directory, parse_command, to_command_class
Constructor Details
#initialize(user = nil, password = nil) ⇒ Credentials
Returns a new instance of Credentials.
5 6 7 8 |
# File 'lib/hapyrus/credentials.rb', line 5 def initialize(user=nil, password=nil) @user = user || ENV['HAPYRUS_LOGIN'] @password = password || ENV['HAPYRUS_PASSWORD'] end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/hapyrus/credentials.rb', line 4 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/hapyrus/credentials.rb', line 4 def user @user end |
Instance Method Details
#authenticate! ⇒ Object
9 10 11 12 |
# File 'lib/hapyrus/credentials.rb', line 9 def authenticate! @authenticated = true write_credentials end |
#authenticated? ⇒ Boolean
13 14 15 |
# File 'lib/hapyrus/credentials.rb', line 13 def authenticated? @authenticated end |
#write_credentials ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hapyrus/credentials.rb', line 16 def write_credentials dir = File.dirname(credentials_file) FileUtils.mkdir_p(dir) File.delete(credentials_file) if FileTest.exists?(credentials_file) File.open(credentials_file, 'w', 0400) do |out| out.puts @user out.puts @password end FileUtils.chmod(0700, dir) end |