Class: PackageCloud::ConfigFile
- Inherits:
-
Object
- Object
- PackageCloud::ConfigFile
- Defined in:
- lib/package_cloud/config_file.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #base_url(username = token, password = "") ⇒ Object
-
#initialize(filename = "~/.packagecloud", url = "packagecloud.io") ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #read_or_create ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(filename = "~/.packagecloud", url = "packagecloud.io") ⇒ ConfigFile
Returns a new instance of ConfigFile.
8 9 10 11 |
# File 'lib/package_cloud/config_file.rb', line 8 def initialize(filename = "~/.packagecloud", url = "packagecloud.io") @filename = File.(filename) @url = url end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/package_cloud/config_file.rb', line 6 def token @token end |
Instance Method Details
#base_url(username = token, password = "") ⇒ Object
30 31 32 |
# File 'lib/package_cloud/config_file.rb', line 30 def base_url(username = token, password = "") "http://#{CGI.escape(username)}:#{CGI.escape(password)}@#{url}" end |
#read_or_create ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/package_cloud/config_file.rb', line 13 def read_or_create if File.exist?(@filename) attrs = JSON.parse(File.read(@filename)) @token = attrs["token"] if attrs.has_key?("token") @url = attrs["url"] if attrs.has_key?("url") else puts "No config file exists at #{@filename}. Login to create one." @token = login_from_console write end end |
#url ⇒ Object
26 27 28 |
# File 'lib/package_cloud/config_file.rb', line 26 def url @url ||= "packagecloud.io" end |