Module: Mesmerize::Authentication
- Defined in:
- lib/mesmerize/authentication.rb
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #client ⇒ Object
- #credentials ⇒ Object
- #login!(user, pass) ⇒ Object
- #logout! ⇒ Object
- #require_authorization! ⇒ Object
- #warn_if_currently_authenticated! ⇒ Object
Instance Method Details
#authenticated? ⇒ Boolean
27 28 29 |
# File 'lib/mesmerize/authentication.rb', line 27 def authenticated? !!credentials end |
#client ⇒ Object
22 23 24 25 |
# File 'lib/mesmerize/authentication.rb', line 22 def client username, password = credentials @client ||= Mesmerize::Client.new(password) end |
#credentials ⇒ Object
5 6 7 |
# File 'lib/mesmerize/authentication.rb', line 5 def credentials Netrc.read[Mesmerize::Client::HOSTNAME] end |
#login!(user, pass) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/mesmerize/authentication.rb', line 9 def login!(user, pass) raise unless user and pass netrc = Netrc.read netrc[Mesmerize::Client::HOSTNAME] = user, pass netrc.save end |
#logout! ⇒ Object
16 17 18 19 20 |
# File 'lib/mesmerize/authentication.rb', line 16 def logout! p netrc = Netrc.read p netrc.delete(Mesmerize::Client::HOSTNAME) netrc.save end |
#require_authorization! ⇒ Object
37 38 39 |
# File 'lib/mesmerize/authentication.rb', line 37 def abort "Authentication required. Please do `mesmerize login` first" unless authenticated? end |
#warn_if_currently_authenticated! ⇒ Object
31 32 33 34 35 |
# File 'lib/mesmerize/authentication.rb', line 31 def warn_if_currently_authenticated! if authenticated? say_warning "You are already authenticated." end end |