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
44 45 46 |
# File 'lib/pgpass.rb', line 44 def database @database end |
#hostname ⇒ Object
Returns the value of attribute hostname
44 45 46 |
# File 'lib/pgpass.rb', line 44 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password
44 45 46 |
# File 'lib/pgpass.rb', line 44 def password @password end |
#port ⇒ Object
Returns the value of attribute port
44 45 46 |
# File 'lib/pgpass.rb', line 44 def port @port end |
#username ⇒ Object
Returns the value of attribute 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
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_hash ⇒ Object
64 65 66 |
# File 'lib/pgpass.rb', line 64 def to_hash Hash[self.class.members.map{|m| self[m] }] end |
#to_url ⇒ Object
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 |