Module: DynamicMigrations::Postgres::Server::Database::Schema::Functions
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/functions.rb
Defined Under Namespace
Classes: FunctionAlreadyExistsError, FunctionDoesNotExistError
Instance Method Summary collapse
-
#add_function(function_name, definition, description: nil) ⇒ Object
create and add a new function from a provided function name.
-
#function(function_name) ⇒ Object
return a function by its name, raises an error if the function does not exist.
-
#functions ⇒ Object
returns an array of all functions in the schema.
- #functions_hash ⇒ Object
-
#has_function?(function_name) ⇒ Boolean
returns true/false representing if a function with the provided name exists.
Instance Method Details
#add_function(function_name, definition, description: nil) ⇒ Object
create and add a new function from a provided function name
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/functions.rb', line 16 def add_function function_name, definition, description: nil raise ExpectedSymbolError, function_name unless function_name.is_a? Symbol if has_function? function_name raise(FunctionAlreadyExistsError, "Function #{function_name} already exists") end included_target = self if included_target.is_a? Schema new_function = @functions[function_name] = Function.new source, included_target, function_name, definition, description: description else raise ModuleIncludedIntoUnexpectedTargetError, included_target end # sort the hash so that the functions are in alphabetical order by name sorted_functions = {} @functions.keys.sort.each do |function_name| sorted_functions[function_name] = @functions[function_name] end @functions = sorted_functions # return the new function new_function end |
#function(function_name) ⇒ Object
return a function by its name, raises an error if the function does not exist
38 39 40 41 42 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/functions.rb', line 38 def function function_name raise ExpectedSymbolError, function_name unless function_name.is_a? Symbol raise FunctionDoesNotExistError unless has_function? function_name @functions[function_name] end |
#functions ⇒ Object
returns an array of all functions in the schema
51 52 53 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/functions.rb', line 51 def functions @functions.values end |
#functions_hash ⇒ Object
55 56 57 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/functions.rb', line 55 def functions_hash @functions end |
#has_function?(function_name) ⇒ Boolean
returns true/false representing if a function with the provided name exists
45 46 47 48 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/functions.rb', line 45 def has_function? function_name raise ExpectedSymbolError, function_name unless function_name.is_a? Symbol @functions.key? function_name end |