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



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

def database
  @database
end

#hostnameObject

Returns the value of attribute hostname

Returns:

  • (Object)

    the current value of hostname



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

def hostname
  @hostname
end

#passwordObject

Returns the value of attribute password

Returns:

  • (Object)

    the current value of password



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

def password
  @password
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



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

def port
  @port
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



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

def username
  @username
end

Class Method Details

.create(hash) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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)


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

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

#complement(other) ⇒ Object



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

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



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

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

#to_hashObject



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

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

#to_urlObject



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

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