class
Analyzer::Crystal::Amber
Defined in:
analyzer/analyzers/crystal/amber.crConstant Summary
-
AMBER_MARKER_RE =
/require\s+"amber"|Amber::|^\s*routes\s+:\w+/m -
get "/path"is the same line in Amber, Kemal and Grip — the DSLs are indistinguishable one line at a time, and this analyzer is handed every.crfile in the scan. Without a file-level gate it read Kemal's, Grip's and Lucky's routes as Amber ones (22 phantom endpoints across the Crystal fixture tree), and swallowed theirpublic_folderdeclarations on the way through.A file that declares Amber routes belongs to an Amber app, so it names the framework:
require "amber"in the fixtures and in an app's entry point,Amber::Server.configurein a realconfig/routes.cr, or theroutes :web dopipeline block, which is Amber's DSL and nobody else's. -
CONTROLLER_ROUTE_RE =
/(?:^|[^.\w])(get|post|put|delete|patch|head|options|ws)\s*(?:\(\s*)?['"](.+?)['"]\s*,\s*\w+,\s*:\w+/ -
Amber prefers
verb "/path", Controller, :action. One combined PCRE2 scan replaces the previous 8 sequential controller-form scans; on miss, the shared simple-route helper covers the controller-less fallback (another single scan). Was 16 unguarded.scancalls per source line. -
NAMESPACE_PATTERN =
/^(\s*)namespace\s+["']([^"']*)["']\s+do\b/ -
namespace "/admin" do … end— Amber's DSL scope macro. -
RESOURCE_ROUTES =
[{"GET", "", :index}, {"GET", "/new", :new}, {"POST", "", :create}, {"GET", "/:id", :show}, {"GET", "/:id/edit", :edit}, {"PUT", "/:id", :update}, {"PATCH", "/:id", :update}, {"DELETE", "/:id", :destroy}] -
Amber's
resourcesmacro expands to the seven RESTful routes below (update is registered for both PUT and PATCH).resource(singular) shares the same action set; the:idsegment is auto-detected as a path param downstream, so we only emit the verb + URL + action here. -
RESOURCES_PATTERN =
/^\s*resources\s+["']([^"']+)["']\s*,\s*([A-Za-z_]\w*(?:::[A-Za-z_]\w*)*)\s*(.*)$/ -
resources "/posts", PostController[, only: …][, except: …]. -
ROUTES_SCOPE_PATTERN =
/^(\s*)routes\s+:\w+(?:\s*,\s*["']([^"']*)["'])?\s+do\b/ -
routes :web, "/admin" do … end— the optional second argument is a path scope that prefixes every route declared inside the block. -
SERVE_STATIC_DISABLED_RE =
Regex.union("serve_static false", "serve_static(false)") -
serve_static false/serve_static(false)— checked on every source line, so the two fixed OR-edString#includes?substring scans are precompiled into a single regex union (one PCRE2 JIT scan per line instead of two naive substring scans).
Class Method Summary
Instance Method Summary
- #analyze
- #analyze_file(path : String) : Array(Endpoint)
- #line_to_endpoint(content : String) : Endpoint
- #line_to_param(content : String) : Param
-
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class FileScanEngine
analyze
analyze,
analyze_file(path : String) : Array(Endpoint)
analyze_file
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.