Class: ActiveRecord::ConnectionAdapters::PostgreSQLViewAlterer
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLViewAlterer
- Includes:
- PostgreSQLExtensions::Utils
- Defined in:
- lib/active_record/postgresql_extensions/views.rb
Constant Summary collapse
- VALID_OPTIONS =
%w{ set_default drop_default owner_to rename_to set_schema set_options reset_options }.freeze
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#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, name, actions, options = {}) ⇒ PostgreSQLViewAlterer
constructor
:nodoc:.
-
#to_sql ⇒ Object
:nodoc:.
Methods included from PostgreSQLExtensions::Utils
#hash_or_array_of_hashes, #options_from_hash_or_string, #strip_heredoc
Constructor Details
#initialize(base, name, actions, options = {}) ⇒ PostgreSQLViewAlterer
:nodoc:
174 175 176 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 174 def initialize(base, name, actions, = {}) #:nodoc: @base, @name, @actions, @options = base, name, actions, end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
162 163 164 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 162 def actions @actions end |
#base ⇒ Object
Returns the value of attribute base.
162 163 164 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 162 def base @base end |
#name ⇒ Object
Returns the value of attribute name.
162 163 164 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 162 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
162 163 164 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 162 def @options end |
Instance Method Details
#to_sql ⇒ Object
:nodoc:
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/active_record/postgresql_extensions/views.rb', line 178 def to_sql #:nodoc: all_sql = [] VALID_OPTIONS.each do |key| key = key.to_sym if actions.key?(key) sql = "ALTER VIEW " if .key?(:if_exists) ActiveRecord::PostgreSQLExtensions::Features.check_feature(:view_if_exists) sql << "IF EXISTS " if [:if_exists] end sql << "#{base.quote_view_name(name)} " sql << case key when :set_default column, expression = actions[:set_default].flatten "ALTER COLUMN #{base.quote_column_name(column)} SET DEFAULT #{expression}" when :drop_default "ALTER COLUMN #{base.quote_column_name(actions[:drop_default])} DROP DEFAULT" when :owner_to "OWNER TO #{base.quote_role(actions[:owner_to])}" when :rename_to "RENAME TO #{base.quote_generic_ignore_scoped_schema(actions[:rename_to])}" when :set_schema "SET SCHEMA #{base.quote_schema(actions[:set_schema])}" when :set_options ActiveRecord::PostgreSQLExtensions::Features.check_feature(:view_set_options) "SET (#{(actions[:set_options])})" if actions[:set_options].present? when :reset_options ActiveRecord::PostgreSQLExtensions::Features.check_feature(:view_set_options) 'RESET (' << Array.wrap(actions[:reset_options]).collect { |value| base.quote_generic(value) }.join(", ") << ')' end all_sql << "#{sql};" end end all_sql.join("\n") end |