Class: Pgpass::Entry

Inherits:
Struct
  • Object
show all
Defined in:
lib/pgpass.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject

Returns the value of attribute database

Returns:

  • (Object)

    the current value of database



45
46
47
# File 'lib/pgpass.rb', line 45

def database
  @database
end

#hostnameObject

Returns the value of attribute hostname

Returns:

  • (Object)

    the current value of hostname



45
46
47
# File 'lib/pgpass.rb', line 45

def hostname
  @hostname
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



45
46
47
# File 'lib/pgpass.rb', line 45

def password
  @password
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



45
46
47
# File 'lib/pgpass.rb', line 45

def port
  @port
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



45
46
47
# File 'lib/pgpass.rb', line 45

def username
  @username
end

Class Method Details

.create(hash) ⇒ Object



46
47
48
# File 'lib/pgpass.rb', line 46

def self.create(hash)
  new(*hash.values_at(*members))
end

Instance Method Details

#==(other) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/pgpass.rb', line 73

def ==(other)
  compare(database, other.database) &&
    compare(username, other.username) &&
    compare(hostname, other.hostname) &&
    compare(port, other.port) &&
    compare(password, other.password)
end

#blank?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/pgpass.rb', line 50

def blank?
  any = hostname || port || database || username || password
  any ? false : true
end

#complement(other) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/pgpass.rb', line 81

def complement(other)
  self.class.create(
    database: complement_one(database, other.database),
    username: complement_one(username, other.username),
    hostname: complement_one(hostname, other.hostname),
    port: complement_one(port, other.port),
    password: complement_one(password, other.password)
  )
end

#merge(other) ⇒ Object



69
70
71
# File 'lib/pgpass.rb', line 69

def merge(other)
  self.class.create(to_hash.merge(other.to_hash))
end

#to_hashObject



65
66
67
# File 'lib/pgpass.rb', line 65

def to_hash
  Hash[self.class.members.map { |m| [m, self[m]] }]
end

#to_urlObject



55
56
57
58
59
60
61
62
63
# File 'lib/pgpass.rb', line 55

def to_url
  uri = URI('postgres:///')
  uri.user = username || ENV['PGUSER'] || Etc.getlogin
  uri.password = password || ENV['PGPASSWORD']
  uri.host = hostname || ENV['PGHOST'] || 'localhost'
  uri.port = (port || ENV['PGPORT'] || 5432).to_i
  uri.path = "/#{database || ENV['PGDATABASE']}"
  uri.to_s
end