Class: PackageCloud::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/package_cloud/config_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.expand_path(filename)
  @url = url
end

Instance Attribute Details

#tokenObject (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_createObject



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 = 
    write
  end
end

#urlObject



26
27
28
# File 'lib/package_cloud/config_file.rb', line 26

def url
  @url ||= "packagecloud.io"
end