Class: ActiveRecord::ConnectionAdapters::PostgreSQLRole
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLRole
- Defined in:
- lib/active_record/postgresql_extensions/roles.rb
Overview
This is a base class for creating and altering ROLEs and is not meant to be used directly.
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#base ⇒ Object
Returns the value of attribute base.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(base, action, name, options = {}) ⇒ PostgreSQLRole
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, action, name, options = {}) ⇒ PostgreSQLRole
:nodoc:
48 49 50 51 52 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 48 def initialize(base, action, name, = {}) #:nodoc: assert_valid_action(action) @base, @action, @name, @options = base, action, name, end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
46 47 48 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 46 def action @action end |
#base ⇒ Object
Returns the value of attribute base.
46 47 48 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 46 def base @base end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 46 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
46 47 48 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 46 def @options end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/active_record/postgresql_extensions/roles.rb', line 54 def to_sql #:nodoc: sql = Array.new if action == :create sql << 'CREATE' else sql << 'ALTER' end sql << "ROLE #{base.quote_role(name)}" if [:superuser] sql << 'SUPERUSER' end if [:create_db] sql << 'CREATEDB' end if [:create_role] sql << 'CREATEROLE' end if .has_key?(:inherit) && ![:inherit] sql << 'NOINHERIT' end if [:login] sql << 'LOGIN' end if [:connection_limit] sql << "CONNECTION LIMIT #{[:connection_limit].to_i}" end if [:password] if .has_key?(:encrypted_password) if [:encrypted_password] sql << 'ENCRYPTED' else sql << 'UNENCRYPTED' end end sql << 'PASSWORD' sql << base.quote([:password]) end if [:valid_until] sql << 'VALID UNTIL' = case [:valid_until] when Date, Time, DateTime [:valid_until].to_s(:sql) else [:valid_until].to_s end sql << base.quote() end if [:in_role].present? sql << 'IN ROLE' sql << Array.wrap([:in_role]).collect { |r| base.quote_role(r) }.join(', ') end if [:role].present? sql << 'ROLE' sql << Array.wrap([:role]).collect { |r| base.quote_role(r) }.join(', ') end if [:admin].present? sql << 'ADMIN' sql << Array.wrap([:admin]).collect { |r| base.quote_role(r) }.join(', ') end "#{sql.join(' ')};" end |