Class: Pgpass::Entry
- Inherits:
-
Struct
- Object
- Struct
- Pgpass::Entry
- Defined in:
- lib/pgpass.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #blank? ⇒ Boolean
- #complement(other) ⇒ Object
- #merge(other) ⇒ Object
- #to_hash ⇒ Object
- #to_url ⇒ Object
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database
45 46 47 |
# File 'lib/pgpass.rb', line 45 def database @database end |
#hostname ⇒ Object
Returns the value of attribute hostname
45 46 47 |
# File 'lib/pgpass.rb', line 45 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password
45 46 47 |
# File 'lib/pgpass.rb', line 45 def password @password end |
#port ⇒ Object
Returns the value of attribute port
45 46 47 |
# File 'lib/pgpass.rb', line 45 def port @port end |
#username ⇒ Object
Returns the value of attribute 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
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_hash ⇒ Object
65 66 67 |
# File 'lib/pgpass.rb', line 65 def to_hash Hash[self.class.members.map { |m| [m, self[m]] }] end |
#to_url ⇒ Object
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 |