Class: ActiveRecord::ConnectionAdapters::PostgreSQLFunctionDefinition
- Inherits:
-
PostgreSQLFunction
- Object
- PostgreSQLFunction
- ActiveRecord::ConnectionAdapters::PostgreSQLFunctionDefinition
- Defined in:
- lib/active_record/postgresql_extensions/functions.rb
Overview
Creates a PostgreSQL function definition. You’re generally going to want to use the create_function
method instead of accessing this class directly.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#language ⇒ Object
Returns the value of attribute language.
-
#returns ⇒ Object
Returns the value of attribute returns.
Attributes inherited from PostgreSQLFunction
Instance Method Summary collapse
-
#initialize(base, name, args, returns, language, body, options = {}) ⇒ PostgreSQLFunctionDefinition
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, name, args, returns, language, body, options = {}) ⇒ PostgreSQLFunctionDefinition
:nodoc:
314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/active_record/postgresql_extensions/functions.rb', line 314 def initialize(base, name, args, returns, language, body, = {}) #:nodoc: assert_valid_behavior([:behavior]) assert_valid_on_null_input([:on_null_input]) assert_valid_security([:security]) @language, @returns, @body = language, returns, body = { :delimiter => '$$' }.merge super(base, name, args, ) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
312 313 314 |
# File 'lib/active_record/postgresql_extensions/functions.rb', line 312 def body @body end |
#language ⇒ Object
Returns the value of attribute language.
312 313 314 |
# File 'lib/active_record/postgresql_extensions/functions.rb', line 312 def language @language end |
#returns ⇒ Object
Returns the value of attribute returns.
312 313 314 |
# File 'lib/active_record/postgresql_extensions/functions.rb', line 312 def returns @returns end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/active_record/postgresql_extensions/functions.rb', line 326 def to_sql #:nodoc: sql = 'CREATE ' sql << 'OR REPLACE ' if [:force] sql << "FUNCTION #{base.quote_function(name)}(#{args}) RETURNS #{returns} AS " if language == 'C' "#{base.quote_function(body[0])}, #{base.quote_generic(body[1])}" else sql << "#{[:delimiter]}\n#{body}\n#{[:delimiter]}\n" end sql << "LANGUAGE #{base.quote_language(language)}\n" sql << " #{[:behavior].to_s.upcase}\n" if [:behavior] sql << " #{[:on_null_input].to_s.upcase}\n" if [:on_null_input] sql << " COST #{[:cost].to_i}\n" if [:cost] sql << " ROWS #{[:rows].to_i}\n" if [:rows] sql << " " << (([:set]) * "\n ") if [:set] "#{sql.strip};" end |