Module: SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::AddColumnOptions
- Defined in:
- lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #add_column_options_with_schema_plus!(sql, options) ⇒ Object
-
#default_expr_valid?(expr) ⇒ Boolean
(abstract) Return true if the passed expression can be used as a column default value.
-
#sql_for_function(function_name) ⇒ Object
(abstract) Return SQL definition for a given canonical function_name symbol.
Class Method Details
.included(base) ⇒ Object
:nodoc:
190 191 192 |
# File 'lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb', line 190 def self.included(base) #:nodoc: base.alias_method_chain :add_column_options!, :schema_plus end |
Instance Method Details
#add_column_options_with_schema_plus!(sql, options) ⇒ Object
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 |
# File 'lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb', line 194 def (sql, ) if () default = [:default] if default.is_a? Hash value = default[:value] expr = sql_for_function(default[:expr]) || default[:expr] if default[:expr] else value = default expr = sql_for_function(default) end if expr raise ArgumentError, "Invalid default expression" unless default_expr_valid?(expr) sql << " DEFAULT #{expr}" # must explicitly check for :null to allow change_column to work on migrations if [:null] == false sql << " NOT NULL" end else (sql, .merge(default: value)) end else (sql, ) end end |
#default_expr_valid?(expr) ⇒ Boolean
(abstract) Return true if the passed expression can be used as a column default value. (For most databases the specific expression doesn’t matter, and the adapter’s function would return a constant true if default expressions are supported or false if they’re not.)
231 |
# File 'lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb', line 231 def default_expr_valid?(expr) raise "Internal Error: Connection adapter didn't override abstract function"; end |
#sql_for_function(function_name) ⇒ Object
(abstract) Return SQL definition for a given canonical function_name symbol. Currently, the only function to support is :now, which should return a DATETIME object for the current time.
236 |
# File 'lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb', line 236 def sql_for_function(function_name) raise "Internal Error: Connection adapter didn't override abstract function"; end |