Module: Arfi::Commands::FunctionsPaths
- Included in:
- Functions
- Defined in:
- lib/arfi/commands/functions_paths.rb,
sig/lib/arfi/commands/functions_paths.rbs
Overview
Path resolution helpers for Functions.
Constant Summary collapse
- ROOT_DIR =
- DEFAULT_SCHEMA =
Instance Method Summary collapse
-
#adapter_canonical_path(root, schema, function_name) ⇒ String
Build the canonical path for an adapter-specific function.
-
#canonical_path(schema, function_name) ⇒ String
Resolve the canonical output path for a function file, respecting adapter option.
-
#function_paths(schema, function_name) ⇒ Array<String>
List all possible filesystem paths where a function file might exist, respecting adapter.
-
#generic_canonical_path(root, schema, function_name) ⇒ String
Build the canonical path for a generic (non-adapter) function.
-
#generic_function_paths(root, function_name) ⇒ Array<String>
List file paths to check when looking for a generic function file.
-
#mysql_function_paths(root, function_name) ⇒ Array<String>
List file paths to check when looking for a MySQL/Trilogy function file.
-
#postgresql_function_paths(root, schema, function_name) ⇒ Array<String>
List file paths to check when looking for a PostgreSQL function file.
Instance Method Details
#adapter_canonical_path(root, schema, function_name) ⇒ String
Build the canonical path for an adapter-specific function.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/arfi/commands/functions_paths.rb', line 70 def adapter_canonical_path(root, schema, function_name) case adapter_opt when 'postgresql' root.join('postgresql', schema || DEFAULT_SCHEMA, "#{function_name}.sql").to_s when 'mysql', 'trilogy' raise ArgumentError, 'Schema-qualified functions are only supported for PostgreSQL.' if schema root.join('mysql', DEFAULT_SCHEMA, "#{function_name}.sql").to_s else raise Arfi::Errors::AdapterNotSupported end end |
#canonical_path(schema, function_name) ⇒ String
Resolve the canonical output path for a function file, respecting adapter option.
15 16 17 18 19 20 21 22 |
# File 'lib/arfi/commands/functions_paths.rb', line 15 def canonical_path(schema, function_name) root = Rails.root.join(ROOT_DIR) if adapter_opt.nil? generic_canonical_path(root, schema, function_name) else adapter_canonical_path(root, schema, function_name) end end |
#function_paths(schema, function_name) ⇒ Array<String>
List all possible filesystem paths where a function file might exist, respecting adapter.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arfi/commands/functions_paths.rb', line 31 def function_paths(schema, function_name) root = Rails.root.join(ROOT_DIR) out = case adapter_opt when nil then generic_function_paths(root, function_name) when 'postgresql' then postgresql_function_paths(root, schema, function_name) when 'mysql', 'trilogy' then mysql_function_paths(root, function_name) else raise Arfi::Errors::AdapterNotSupported end out.uniq end |
#generic_canonical_path(root, schema, function_name) ⇒ String
Build the canonical path for a generic (non-adapter) function.
Generic functions can only target the 'public' schema.
52 53 54 55 56 57 58 59 |
# File 'lib/arfi/commands/functions_paths.rb', line 52 def generic_canonical_path(root, schema, function_name) sch = schema || DEFAULT_SCHEMA unless sch == DEFAULT_SCHEMA raise ArgumentError, "Generic functions can only target schema '#{DEFAULT_SCHEMA}'" end root.join(DEFAULT_SCHEMA, "#{function_name}.sql").to_s end |
#generic_function_paths(root, function_name) ⇒ Array<String>
List file paths to check when looking for a generic function file.
89 90 91 92 93 94 |
# File 'lib/arfi/commands/functions_paths.rb', line 89 def generic_function_paths(root, function_name) [ root.join(DEFAULT_SCHEMA, "#{function_name}.sql").to_s, root.join("#{function_name}.sql").to_s ] end |
#mysql_function_paths(root, function_name) ⇒ Array<String>
List file paths to check when looking for a MySQL/Trilogy function file.
121 122 123 124 125 126 127 128 |
# File 'lib/arfi/commands/functions_paths.rb', line 121 def mysql_function_paths(root, function_name) [ root.join('mysql', DEFAULT_SCHEMA, "#{function_name}.sql").to_s, root.join('mysql', "#{function_name}.sql").to_s, root.join(DEFAULT_SCHEMA, "#{function_name}.sql").to_s, root.join("#{function_name}.sql").to_s ] end |
#postgresql_function_paths(root, schema, function_name) ⇒ Array<String>
List file paths to check when looking for a PostgreSQL function file.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/arfi/commands/functions_paths.rb', line 103 def postgresql_function_paths(root, schema, function_name) sch = schema || DEFAULT_SCHEMA out = [ root.join('postgresql', sch, "#{function_name}.sql").to_s, root.join('postgresql', DEFAULT_SCHEMA, "#{function_name}.sql").to_s, root.join(DEFAULT_SCHEMA, "#{function_name}.sql").to_s, root.join("#{function_name}.sql").to_s ] out.insert(2, root.join('postgresql', "#{function_name}.sql").to_s) if sch == DEFAULT_SCHEMA out end |