class
Analyzer::Groovy::Grails
- Analyzer::Groovy::Grails
- Analyzer
- Reference
- Object
Overview
Grails follows a convention-over-configuration layout where each
controller class under grails-app/controllers/ exposes its action
methods as URL endpoints. The default URL mapping is
"/$controller/$action?/$id?(.$format)?", so we surface every
action method as /<controller>/<action> (the controller name is
the class name with the Controller suffix dropped and the first
letter lowercased).
Two action styles are handled:
- Method form:
def show() { ... } - Closure form:
def show = { ... }(legacy Grails)
When the controller declares
static allowedMethods = [save: 'POST', update: ['PUT', 'PATCH']]
those restrictions are honored; otherwise actions are emitted as
GET (the default Grails dispatch verb when no restriction is set).
UrlMappings.groovy is also scanned for explicit string-based mappings
of the form
get '/api/users'(controller: 'user', action: 'list')
which are surfaced as additional endpoints. It lives under
grails-app/conf/ on Grails 1.x/2.x and grails-app/controllers/ on
Grails 3+; both locations are handled. Per-verb action = [GET: ..., PUT: ...] dispatch maps and ${name} GString path variables are recognized,
while bare-status-code ("404", "500") error mappings are excluded.
Defined in:
analyzer/analyzers/groovy/grails.crConstant Summary
-
BODY_ARGS_KEY_RE =
Regex.union("controller:", "action:", "view:", "uri:") -
One precompiled
Regex.unionscan (PCRE2 JIT) replaces the four OR-edString#includes?scans that used to gate every verbless paren-form mapping match in emit_mapping_endpoints (runs once per match, so a UrlMappings file with many entries repeats this often).unionauto-escapes each literal, so this is exactly equivalent to the OR-chain it replaces. -
DEFAULT_METHODS =
["GET"] -
HTTP_METHODS =
["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"] of ::String -
RESOURCES_ENDPOINTS =
[{suffix: "", method: "GET"}, {suffix: "", method: "POST"}, {suffix: "/:id", method: "GET"}, {suffix: "/:id", method: "PUT"}, {suffix: "/:id", method: "PATCH"}, {suffix: "/:id", method: "DELETE"}] -
Endpoints generated by
(resources: "name")shortcuts inUrlMappings.groovy. Each tuple is suffix appended to the base URL plus the verb. -
RESTFUL_ACTIONS =
[{name: "index", method: "GET"}, {name: "show", method: "GET"}, {name: "save", method: "POST"}, {name: "update", method: "PUT"}, {name: "patch", method: "PATCH"}, {name: "delete", method: "DELETE"}] -
Actions inherited from
RestfulController<T>(Grails REST base). -
SCAFFOLD_ACTIONS =
[{name: "index", method: "GET"}, {name: "show", method: "GET"}, {name: "create", method: "GET"}, {name: "save", method: "POST"}, {name: "edit", method: "GET"}, {name: "update", method: "PUT"}, {name: "delete", method: "DELETE"}] -
Actions added implicitly by
static scaffold = X(Grails legacy CRUD scaffolding). -
SKIP_ACTION_NAMES =
["beforeInterceptor", "afterInterceptor", "afterView", "allowedMethods", "scaffold", "defaultAction", "errors", "response", "request", "params", "responseFormats", "namespace", "transactional"] of ::String -
URL_MAPPINGS_DIR_RE =
Regex.union("/grails-app/conf/", "/grails-app/controllers/") -
One precompiled
Regex.unionscan (PCRE2 JIT) replaces the two OR-edString#includes?scansurl_mappings_path?used to run over every candidate path -- Crystal'sincludes?is not Boyer-Moore accelerated, so a single regex pass is cheaper than two substring scans.unionauto-escapes each literal, so this is exactly equivalent to the OR-chain it replaces.
Class Method Summary
Instance Method Summary
- #analyze
-
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class Analyzer
analyze
analyze,
base_path : String
base_path,
base_paths : Array(String)
base_paths,
base_relative_path(path : String) : String
base_relative_path,
callees_needed? : Bool
callees_needed?,
content_matches?(content : String, markers : Regex) : Bool
content_matches?,
http_header_name(name : String) : String | Nil
http_header_name,
line_number_for_index(content : String, char_index : Int32) : Int32
line_number_for_index,
logger : NoirLogger
logger,
parallel_analyze(files : Array(String), &block : String -> Nil)
parallel_analyze,
read_file_content(path : String) : String
read_file_content,
result : Array(Endpoint)
result,
tech : String
tech,
unique_params(params : Array(Param)) : Array(Param)
unique_params,
url : String
url,
web_root_path(path : String, markers : Array(String)) : String
web_root_path
Constructor methods inherited from class Analyzer
new(options : Hash(String, YAML::Any))
new
Macros inherited from class Analyzer
analyzer_for(tech)
analyzer_for
Instance methods inherited from module FileHelper
all_files : Array(String)
all_files,
get_files_by_basename(basename : String) : Array(String)
get_files_by_basename,
get_files_by_extension(extension : String) : Array(String)
get_files_by_extension,
get_files_by_extensions(extensions : Array(String)) : Array(String)
get_files_by_extensions,
get_files_by_prefix(prefix : String) : Array(String)
get_files_by_prefix,
get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String)
get_files_by_prefix_and_extension,
get_files_by_relative_path(relative_path : String, root : String = "") : Array(String)
get_files_by_relative_path,
get_public_dir_files(base_path : String, folder : String) : Array(String)
get_public_dir_files,
get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String)
get_public_files,
walked_path(expanded : String) : String
walked_path
Class Method Detail
Instance Method Detail
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.