Fix Lint/WhitespaceAroundMacroExpression type of Ameba issues

This commit is contained in:
Sijawusz Pur Rahnama 2026-01-11 22:32:28 +01:00
parent 068151a664
commit 3d6f266827
12 changed files with 163 additions and 163 deletions

View File

@ -59,7 +59,7 @@ end
# Get relative file path to a file within the static_assets_handler folder
macro get_file_path(basename)
"spec/http_server/handlers/static_assets_handler/#{ {{basename}} }"
"spec/http_server/handlers/static_assets_handler/#{ {{ basename }} }"
end
Spectator.describe StaticAssetsHandler do

View File

@ -93,7 +93,7 @@ struct ChannelVideo
def to_tuple
{% begin %}
{
{{@type.instance_vars.map(&.name).splat}}
{{ @type.instance_vars.map(&.name).splat }}
}
{% end %}
end

View File

@ -58,7 +58,7 @@ struct ConfigPreferences
def to_tuple
{% begin %}
{
{{(@type.instance_vars.map { |var| "#{var.name}: #{var.name}".id }).splat}}
{{ (@type.instance_vars.map { |var| "#{var.name}: #{var.name}".id }).splat }}
}
{% end %}
end
@ -212,14 +212,14 @@ class Config
{% for ivar in Config.instance_vars %}
{% env_id = "INVIDIOUS_#{ivar.id.upcase}" %}
if ENV.has_key?({{env_id}})
env_value = ENV.fetch({{env_id}})
if ENV.has_key?({{ env_id }})
env_value = ENV.fetch({{ env_id }})
success = false
# Use YAML converter if specified
{% ann = ivar.annotation(::YAML::Field) %}
{% if ann && ann[:converter] %}
config.{{ivar.id}} = {{ann[:converter]}}.from_yaml(YAML::ParseContext.new, YAML::Nodes.parse(ENV.fetch({{env_id}})).nodes[0])
config.{{ ivar.id }} = {{ ann[:converter] }}.from_yaml(YAML::ParseContext.new, YAML::Nodes.parse(ENV.fetch({{ env_id }})).nodes[0])
success = true
# Use regular YAML parser otherwise
@ -227,10 +227,10 @@ class Config
{% ivar_types = ivar.type.union? ? ivar.type.union_types : [ivar.type] %}
# Sort types to avoid parsing nulls and numbers as strings
{% ivar_types = ivar_types.sort_by { |ivar_type| ivar_type == Nil ? 0 : ivar_type == Int32 ? 1 : 2 } %}
{{ivar_types}}.each do |ivar_type|
{{ ivar_types }}.each do |ivar_type|
if !success
begin
config.{{ivar.id}} = ivar_type.from_yaml(env_value)
config.{{ ivar.id }} = ivar_type.from_yaml(env_value)
success = true
rescue
# nop
@ -241,14 +241,14 @@ class Config
# Exit on fail
if !success
puts %(Config.{{ivar.id}} failed to parse #{env_value} as {{ivar.type}})
puts %(Config.{{ ivar.id }} failed to parse #{env_value} as {{ ivar.type }})
exit(1)
end
end
# Warn when any config attribute is set to "CHANGE_ME!!"
if config.{{ivar.id}} == "CHANGE_ME!!"
puts "Config: The value of '#{ {{ivar.stringify}} }' needs to be changed!!"
if config.{{ ivar.id }} == "CHANGE_ME!!"
puts "Config: The value of '#{ {{ ivar.stringify }} }' needs to be changed!!"
exit(1)
end
{% end %}

View File

@ -41,11 +41,11 @@ module Invidious::Frontend::SearchFilters
str << "\t\t\t\t<div class=\"filter-column\"><fieldset>\n"
str << "\t\t\t\t\t<legend><div class=\"filter-name underlined\">"
str << translate(locale, "search_filters_{{name}}_label")
str << translate(locale, "search_filters_{{ name }}_label")
str << "</div></legend>\n"
str << "\t\t\t\t\t<div class=\"filter-options\">\n"
make_{{name}}_filter_options(str, filters.{{name}}, locale)
make_{{ name }}_filter_options(str, filters.{{ name }}, locale)
str << "\t\t\t\t\t</div>"
str << "\t\t\t\t</fieldset></div>\n"
@ -57,12 +57,12 @@ module Invidious::Frontend::SearchFilters
{% date = value.underscore %}
str << "\t\t\t\t\t\t<div>"
str << "<input type='radio' name='date' id='filter-date-{{date}}' value='{{date}}'"
str << " checked" if value.{{date}}?
str << "<input type='radio' name='date' id='filter-date-{{ date }}' value='{{ date }}'"
str << " checked" if value.{{ date }}?
str << '>'
str << "<label for='filter-date-{{date}}'>"
str << translate(locale, "search_filters_date_option_{{date}}")
str << "<label for='filter-date-{{ date }}'>"
str << translate(locale, "search_filters_date_option_{{ date }}")
str << "</label></div>\n"
{% end %}
end
@ -73,12 +73,12 @@ module Invidious::Frontend::SearchFilters
{% type = value.underscore %}
str << "\t\t\t\t\t\t<div>"
str << "<input type='radio' name='type' id='filter-type-{{type}}' value='{{type}}'"
str << " checked" if value.{{type}}?
str << "<input type='radio' name='type' id='filter-type-{{ type }}' value='{{ type }}'"
str << " checked" if value.{{ type }}?
str << '>'
str << "<label for='filter-type-{{type}}'>"
str << translate(locale, "search_filters_type_option_{{type}}")
str << "<label for='filter-type-{{ type }}'>"
str << translate(locale, "search_filters_type_option_{{ type }}")
str << "</label></div>\n"
{% end %}
end
@ -89,12 +89,12 @@ module Invidious::Frontend::SearchFilters
{% duration = value.underscore %}
str << "\t\t\t\t\t\t<div>"
str << "<input type='radio' name='duration' id='filter-duration-{{duration}}' value='{{duration}}'"
str << " checked" if value.{{duration}}?
str << "<input type='radio' name='duration' id='filter-duration-{{ duration }}' value='{{ duration }}'"
str << " checked" if value.{{ duration }}?
str << '>'
str << "<label for='filter-duration-{{duration}}'>"
str << translate(locale, "search_filters_duration_option_{{duration}}")
str << "<label for='filter-duration-{{ duration }}'>"
str << translate(locale, "search_filters_duration_option_{{ duration }}")
str << "</label></div>\n"
{% end %}
end
@ -106,12 +106,12 @@ module Invidious::Frontend::SearchFilters
{% feature = value.underscore %}
str << "\t\t\t\t\t\t<div>"
str << "<input type='checkbox' name='features' id='filter-feature-{{feature}}' value='{{feature}}'"
str << " checked" if value.{{feature}}?
str << "<input type='checkbox' name='features' id='filter-feature-{{ feature }}' value='{{ feature }}'"
str << " checked" if value.{{ feature }}?
str << '>'
str << "<label for='filter-feature-{{feature}}'>"
str << translate(locale, "search_filters_features_option_{{feature}}")
str << "<label for='filter-feature-{{ feature }}'>"
str << translate(locale, "search_filters_features_option_{{ feature }}")
str << "</label></div>\n"
{% end %}
{% end %}
@ -123,12 +123,12 @@ module Invidious::Frontend::SearchFilters
{% sort = value.underscore %}
str << "\t\t\t\t\t\t<div>"
str << "<input type='radio' name='sort' id='filter-sort-{{sort}}' value='{{sort}}'"
str << " checked" if value.{{sort}}?
str << "<input type='radio' name='sort' id='filter-sort-{{ sort }}' value='{{ sort }}'"
str << " checked" if value.{{ sort }}?
str << '>'
str << "<label for='filter-sort-{{sort}}'>"
str << translate(locale, "search_filters_sort_option_{{sort}}")
str << "<label for='filter-sort-{{ sort }}'>"
str << translate(locale, "search_filters_sort_option_{{ sort }}")
str << "</label></div>\n"
{% end %}
end

View File

@ -3,7 +3,7 @@
# -------------------
macro error_template(*args)
error_template_helper(env, {{args.splat}})
error_template_helper(env, {{ args.splat }})
end
def github_details(summary : String, content : String)
@ -106,7 +106,7 @@ end
# -------------------
macro error_atom(*args)
error_atom_helper(env, {{args.splat}})
error_atom_helper(env, {{ args.splat }})
end
def error_atom_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception)
@ -132,7 +132,7 @@ end
# -------------------
macro error_json(*args)
error_json_helper(env, {{args.splat}})
error_json_helper(env, {{ args.splat }})
end
def error_json_helper(

View File

@ -2,10 +2,10 @@ module HTTP::Handler
@@exclude_routes_tree = Radix::Tree(String).new
macro exclude(paths, method = "GET")
class_name = {{@type.name}}
method_downcase = {{method.downcase}}
class_name = {{ @type.name }}
method_downcase = {{ method.downcase }}
class_name_method = "#{class_name}/#{method_downcase}"
({{paths}}).each do |path|
({{ paths }}).each do |path|
@@exclude_routes_tree.add class_name_method + path, '/' + method_downcase + path
end
end
@ -21,7 +21,7 @@ end
class Kemal::RouteHandler
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
exclude ["/api/v1/*"], {{method}}
exclude ["/api/v1/*"], {{ method }}
{% end %}
# Processes the route if it's a match. Otherwise renders 404.
@ -45,7 +45,7 @@ end
class Kemal::ExceptionHandler
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
exclude ["/api/v1/*"], {{method}}
exclude ["/api/v1/*"], {{ method }}
{% end %}
private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32)
@ -73,7 +73,7 @@ end
class AuthHandler < Kemal::Handler
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
only ["/api/v1/auth/*"], {{method}}
only ["/api/v1/auth/*"], {{ method }}
{% end %}
def call(env)
@ -122,7 +122,7 @@ end
class APIHandler < Kemal::Handler
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
only ["/api/v1/*"], {{method}}
only ["/api/v1/*"], {{ method }}
{% end %}
exclude ["/api/v1/auth/notifications"], "GET"
exclude ["/api/v1/auth/notifications"], "POST"

View File

@ -56,9 +56,9 @@ class Invidious::LogHandler < Kemal::BaseLogHandler
end
{% for level in %w(trace debug info warn error fatal) %}
def {{level.id}}(message : String)
if LogLevel::{{level.id.capitalize}} >= @level
puts("#{Time.utc} [{{level.id}}] #{message}".colorize(color(LogLevel::{{level.id.capitalize}})))
def {{ level.id }}(message : String)
if LogLevel::{{ level.id.capitalize }} >= @level
puts("#{Time.utc} [{{ level.id }}] #{message}".colorize(color(LogLevel::{{ level.id.capitalize }})))
end
end
{% end %}

View File

@ -49,24 +49,24 @@ module JSON::Serializable
end
macro templated(_filename, template = "template", navbar_search = true)
navbar_search = {{navbar_search}}
navbar_search = {{ navbar_search }}
{{ filename = "src/invidious/views/" + _filename + ".ecr" }}
{{ layout = "src/invidious/views/" + template + ".ecr" }}
__content_filename__ = {{filename}}
render {{filename}}, {{layout}}
__content_filename__ = {{ filename }}
render {{ filename }}, {{ layout }}
end
macro rendered(filename)
render("src/invidious/views/#{{{filename}}}.ecr")
render("src/invidious/views/#{{{ filename }}}.ecr")
end
# Similar to Kemals halt method but works in a
# method.
macro haltf(env, status_code = 200, response = "")
{{env}}.response.status_code = {{status_code}}
{{env}}.response.print {{response}}
{{env}}.response.close
{{ env }}.response.status_code = {{ status_code }}
{{ env }}.response.print {{ response }}
{{ env }}.response.close
return
end

View File

@ -106,7 +106,7 @@ module Invidious::HttpServer
# Can be removed once https://github.com/crystal-lang/crystal/issues/15817 is fixed.
private def serve_file_range(context : HTTP::Server::Context, file : IO, range_header : String, file_info)
# Paste in the body of inherited serve_file_range
{{@type.superclass.methods.select(&.name.==("serve_file_range"))[0].body}}
{{ @type.superclass.methods.select(&.name.==("serve_file_range"))[0].body }}
end
# Clear cached files.

View File

@ -3,12 +3,12 @@ module Invidious::Routing
{% for http_method in {"get", "post", "delete", "options", "patch", "put"} %}
macro {{http_method.id}}(path, controller, method = :handle)
macro {{ http_method.id }}(path, controller, method = :handle)
unless Kemal::Utils.path_starts_with_slash?(\{{path}})
raise Kemal::Exceptions::InvalidPathStartException.new({{http_method}}, \{{path}})
raise Kemal::Exceptions::InvalidPathStartException.new({{ http_method }}, \{{path}})
end
Kemal::RouteHandler::INSTANCE.add_route({{http_method.upcase}}, \{{path}}) do |env|
Kemal::RouteHandler::INSTANCE.add_route({{ http_method.upcase }}, \{{path}}) do |env|
\{{ controller }}.\{{ method.id }}(env)
end
end
@ -238,91 +238,91 @@ module Invidious::Routing
def register_api_v1_routes
{% begin %}
{{namespace = Routes::API::V1}}
{{ namespace = Routes::API::V1 }}
# Videos
get "/api/v1/videos/:id", {{namespace}}::Videos, :videos
get "/api/v1/storyboards/:id", {{namespace}}::Videos, :storyboards
get "/api/v1/captions/:id", {{namespace}}::Videos, :captions
get "/api/v1/annotations/:id", {{namespace}}::Videos, :annotations
get "/api/v1/comments/:id", {{namespace}}::Videos, :comments
get "/api/v1/clips/:id", {{namespace}}::Videos, :clips
get "/api/v1/transcripts/:id", {{namespace}}::Videos, :transcripts
get "/api/v1/videos/:id", {{ namespace }}::Videos, :videos
get "/api/v1/storyboards/:id", {{ namespace }}::Videos, :storyboards
get "/api/v1/captions/:id", {{ namespace }}::Videos, :captions
get "/api/v1/annotations/:id", {{ namespace }}::Videos, :annotations
get "/api/v1/comments/:id", {{ namespace }}::Videos, :comments
get "/api/v1/clips/:id", {{ namespace }}::Videos, :clips
get "/api/v1/transcripts/:id", {{ namespace }}::Videos, :transcripts
# Feeds
get "/api/v1/trending", {{namespace}}::Feeds, :trending
get "/api/v1/popular", {{namespace}}::Feeds, :popular
get "/api/v1/trending", {{ namespace }}::Feeds, :trending
get "/api/v1/popular", {{ namespace }}::Feeds, :popular
# Channels
get "/api/v1/channels/:ucid", {{namespace}}::Channels, :home
get "/api/v1/channels/:ucid/latest", {{namespace}}::Channels, :latest
get "/api/v1/channels/:ucid/videos", {{namespace}}::Channels, :videos
get "/api/v1/channels/:ucid/shorts", {{namespace}}::Channels, :shorts
get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams
get "/api/v1/channels/:ucid/podcasts", {{namespace}}::Channels, :podcasts
get "/api/v1/channels/:ucid/releases", {{namespace}}::Channels, :releases
get "/api/v1/channels/:ucid/courses", {{namespace}}::Channels, :courses
get "/api/v1/channels/:ucid/playlists", {{namespace}}::Channels, :playlists
get "/api/v1/channels/:ucid/community", {{namespace}}::Channels, :community
get "/api/v1/channels/:ucid/posts", {{namespace}}::Channels, :community
get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels
get "/api/v1/channels/:ucid/search", {{namespace}}::Channels, :search
get "/api/v1/channels/:ucid", {{ namespace }}::Channels, :home
get "/api/v1/channels/:ucid/latest", {{ namespace }}::Channels, :latest
get "/api/v1/channels/:ucid/videos", {{ namespace }}::Channels, :videos
get "/api/v1/channels/:ucid/shorts", {{ namespace }}::Channels, :shorts
get "/api/v1/channels/:ucid/streams", {{ namespace }}::Channels, :streams
get "/api/v1/channels/:ucid/podcasts", {{ namespace }}::Channels, :podcasts
get "/api/v1/channels/:ucid/releases", {{ namespace }}::Channels, :releases
get "/api/v1/channels/:ucid/courses", {{ namespace }}::Channels, :courses
get "/api/v1/channels/:ucid/playlists", {{ namespace }}::Channels, :playlists
get "/api/v1/channels/:ucid/community", {{ namespace }}::Channels, :community
get "/api/v1/channels/:ucid/posts", {{ namespace }}::Channels, :community
get "/api/v1/channels/:ucid/channels", {{ namespace }}::Channels, :channels
get "/api/v1/channels/:ucid/search", {{ namespace }}::Channels, :search
# Posts
get "/api/v1/post/:id", {{namespace}}::Channels, :post
get "/api/v1/post/:id/comments", {{namespace}}::Channels, :post_comments
get "/api/v1/post/:id", {{ namespace }}::Channels, :post
get "/api/v1/post/:id/comments", {{ namespace }}::Channels, :post_comments
# 301 redirects to new /api/v1/channels/community/:ucid and /:ucid/community
get "/api/v1/channels/comments/:ucid", {{namespace}}::Channels, :channel_comments_redirect
get "/api/v1/channels/:ucid/comments", {{namespace}}::Channels, :channel_comments_redirect
get "/api/v1/channels/comments/:ucid", {{ namespace }}::Channels, :channel_comments_redirect
get "/api/v1/channels/:ucid/comments", {{ namespace }}::Channels, :channel_comments_redirect
# Search
get "/api/v1/search", {{namespace}}::Search, :search
get "/api/v1/search/suggestions", {{namespace}}::Search, :search_suggestions
get "/api/v1/hashtag/:hashtag", {{namespace}}::Search, :hashtag
get "/api/v1/search", {{ namespace }}::Search, :search
get "/api/v1/search/suggestions", {{ namespace }}::Search, :search_suggestions
get "/api/v1/hashtag/:hashtag", {{ namespace }}::Search, :hashtag
# Authenticated
get "/api/v1/auth/preferences", {{namespace}}::Authenticated, :get_preferences
post "/api/v1/auth/preferences", {{namespace}}::Authenticated, :set_preferences
get "/api/v1/auth/preferences", {{ namespace }}::Authenticated, :get_preferences
post "/api/v1/auth/preferences", {{ namespace }}::Authenticated, :set_preferences
get "/api/v1/auth/export/invidious", {{namespace}}::Authenticated, :export_invidious
post "/api/v1/auth/import/invidious", {{namespace}}::Authenticated, :import_invidious
get "/api/v1/auth/export/invidious", {{ namespace }}::Authenticated, :export_invidious
post "/api/v1/auth/import/invidious", {{ namespace }}::Authenticated, :import_invidious
get "/api/v1/auth/history", {{namespace}}::Authenticated, :get_history
post "/api/v1/auth/history/:id", {{namespace}}::Authenticated, :mark_watched
delete "/api/v1/auth/history/:id", {{namespace}}::Authenticated, :mark_unwatched
delete "/api/v1/auth/history", {{namespace}}::Authenticated, :clear_history
get "/api/v1/auth/history", {{ namespace }}::Authenticated, :get_history
post "/api/v1/auth/history/:id", {{ namespace }}::Authenticated, :mark_watched
delete "/api/v1/auth/history/:id", {{ namespace }}::Authenticated, :mark_unwatched
delete "/api/v1/auth/history", {{ namespace }}::Authenticated, :clear_history
get "/api/v1/auth/feed", {{namespace}}::Authenticated, :feed
get "/api/v1/auth/feed", {{ namespace }}::Authenticated, :feed
get "/api/v1/auth/subscriptions", {{namespace}}::Authenticated, :get_subscriptions
post "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :subscribe_channel
delete "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :unsubscribe_channel
get "/api/v1/auth/subscriptions", {{ namespace }}::Authenticated, :get_subscriptions
post "/api/v1/auth/subscriptions/:ucid", {{ namespace }}::Authenticated, :subscribe_channel
delete "/api/v1/auth/subscriptions/:ucid", {{ namespace }}::Authenticated, :unsubscribe_channel
get "/api/v1/auth/playlists", {{namespace}}::Authenticated, :list_playlists
post "/api/v1/auth/playlists", {{namespace}}::Authenticated, :create_playlist
patch "/api/v1/auth/playlists/:plid",{{namespace}}:: Authenticated, :update_playlist_attribute
delete "/api/v1/auth/playlists/:plid", {{namespace}}::Authenticated, :delete_playlist
post "/api/v1/auth/playlists/:plid/videos", {{namespace}}::Authenticated, :insert_video_into_playlist
delete "/api/v1/auth/playlists/:plid/videos/:index", {{namespace}}::Authenticated, :delete_video_in_playlist
get "/api/v1/auth/playlists", {{ namespace }}::Authenticated, :list_playlists
post "/api/v1/auth/playlists", {{ namespace }}::Authenticated, :create_playlist
patch "/api/v1/auth/playlists/:plid",{{ namespace }}:: Authenticated, :update_playlist_attribute
delete "/api/v1/auth/playlists/:plid", {{ namespace }}::Authenticated, :delete_playlist
post "/api/v1/auth/playlists/:plid/videos", {{ namespace }}::Authenticated, :insert_video_into_playlist
delete "/api/v1/auth/playlists/:plid/videos/:index", {{ namespace }}::Authenticated, :delete_video_in_playlist
get "/api/v1/auth/tokens", {{namespace}}::Authenticated, :get_tokens
post "/api/v1/auth/tokens/register", {{namespace}}::Authenticated, :register_token
post "/api/v1/auth/tokens/unregister", {{namespace}}::Authenticated, :unregister_token
get "/api/v1/auth/tokens", {{ namespace }}::Authenticated, :get_tokens
post "/api/v1/auth/tokens/register", {{ namespace }}::Authenticated, :register_token
post "/api/v1/auth/tokens/unregister", {{ namespace }}::Authenticated, :unregister_token
if CONFIG.enable_user_notifications
get "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications
post "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications
get "/api/v1/auth/notifications", {{ namespace }}::Authenticated, :notifications
post "/api/v1/auth/notifications", {{ namespace }}::Authenticated, :notifications
end
# Misc
get "/api/v1/stats", {{namespace}}::Misc, :stats
get "/api/v1/playlists/:plid", {{namespace}}::Misc, :get_playlist
get "/api/v1/auth/playlists/:plid", {{namespace}}::Misc, :get_playlist
get "/api/v1/mixes/:rdid", {{namespace}}::Misc, :mixes
get "/api/v1/resolveurl", {{namespace}}::Misc, :resolve_url
get "/api/v1/stats", {{ namespace }}::Misc, :stats
get "/api/v1/playlists/:plid", {{ namespace }}::Misc, :get_playlist
get "/api/v1/auth/playlists/:plid", {{ namespace }}::Misc, :get_playlist
get "/api/v1/mixes/:rdid", {{ namespace }}::Misc, :mixes
get "/api/v1/resolveurl", {{ namespace }}::Misc, :resolve_url
{% end %}
end
end

View File

@ -195,37 +195,37 @@ struct Video
# Macros defining getters/setters for various types of data
private macro getset_string(name)
# Return {{name.stringify}} from `info`
def {{name.id.underscore}} : String
return info[{{name.stringify}}]?.try &.as_s || ""
# Return {{ name.stringify }} from `info`
def {{ name.id.underscore }} : String
return info[{{ name.stringify }}]?.try &.as_s || ""
end
# Update {{name.stringify}} into `info`
def {{name.id.underscore}}=(value : String)
info[{{name.stringify}}] = JSON::Any.new(value)
# Update {{ name.stringify }} into `info`
def {{ name.id.underscore }}=(value : String)
info[{{ name.stringify }}] = JSON::Any.new(value)
end
{% if flag?(:debug_macros) %} {{debug}} {% end %}
{% if flag?(:debug_macros) %} {{ debug }} {% end %}
end
private macro getset_string_array(name)
# Return {{name.stringify}} from `info`
def {{name.id.underscore}} : Array(String)
return info[{{name.stringify}}]?.try &.as_a.map &.as_s || [] of String
# Return {{ name.stringify }} from `info`
def {{ name.id.underscore }} : Array(String)
return info[{{ name.stringify }}]?.try &.as_a.map &.as_s || [] of String
end
# Update {{name.stringify}} into `info`
def {{name.id.underscore}}=(value : Array(String))
info[{{name.stringify}}] = JSON::Any.new(value)
# Update {{ name.stringify }} into `info`
def {{ name.id.underscore }}=(value : Array(String))
info[{{ name.stringify }}] = JSON::Any.new(value)
end
{% if flag?(:debug_macros) %} {{debug}} {% end %}
{% if flag?(:debug_macros) %} {{ debug }} {% end %}
end
{% for op, type in {i32: Int32, i64: Int64} %}
private macro getset_{{op}}(name)
def \{{name.id.underscore}} : {{type}}
return info[\{{name.stringify}}]?.try &.as_i64.to_{{op}} || 0_{{op}}
private macro getset_{{ op }}(name)
def \{{name.id.underscore}} : {{ type }}
return info[\{{name.stringify}}]?.try &.as_i64.to_{{ op }} || 0_{{ op }}
end
def \{{name.id.underscore}}=(value : Int)
@ -237,32 +237,32 @@ struct Video
{% end %}
private macro getset_bool(name)
# Return {{name.stringify}} from `info`
def {{name.id.underscore}} : Bool
return info[{{name.stringify}}]?.try &.as_bool || false
# Return {{ name.stringify }} from `info`
def {{ name.id.underscore }} : Bool
return info[{{ name.stringify }}]?.try &.as_bool || false
end
# Update {{name.stringify}} into `info`
def {{name.id.underscore}}=(value : Bool)
info[{{name.stringify}}] = JSON::Any.new(value)
# Update {{ name.stringify }} into `info`
def {{ name.id.underscore }}=(value : Bool)
info[{{ name.stringify }}] = JSON::Any.new(value)
end
{% if flag?(:debug_macros) %} {{debug}} {% end %}
{% if flag?(:debug_macros) %} {{ debug }} {% end %}
end
# Macro to generate ? and = accessor methods for attributes in `info`
private macro predicate_bool(method_name, name)
# Return {{name.stringify}} from `info`
def {{method_name.id.underscore}}? : Bool
return info[{{name.stringify}}]?.try &.as_bool || false
# Return {{ name.stringify }} from `info`
def {{ method_name.id.underscore }}? : Bool
return info[{{ name.stringify }}]?.try &.as_bool || false
end
# Update {{name.stringify}} into `info`
def {{method_name.id.underscore}}=(value : Bool)
info[{{name.stringify}}] = JSON::Any.new(value)
# Update {{ name.stringify }} into `info`
def {{ method_name.id.underscore }}=(value : Bool)
info[{{ name.stringify }}] = JSON::Any.new(value)
end
{% if flag?(:debug_macros) %} {{debug}} {% end %}
{% if flag?(:debug_macros) %} {{ debug }} {% end %}
end
# Method definitions, using the macros above

View File

@ -40,8 +40,8 @@ private module Parsers
begin
return parse_internal(*args)
rescue ex
LOGGER.debug("#{{{@type.name}}}: Failed to render item.")
LOGGER.debug("#{{{@type.name}}}: Got exception: #{ex.message}")
LOGGER.debug("#{{{ @type.name }}}: Failed to render item.")
LOGGER.debug("#{{{ @type.name }}}: Got exception: #{ex.message}")
ProblematicTimelineItem.new(
parse_exception: ex
)
@ -173,7 +173,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -240,7 +240,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -289,7 +289,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -334,7 +334,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -395,7 +395,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -467,7 +467,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -496,7 +496,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -527,7 +527,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -626,7 +626,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -704,7 +704,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -762,7 +762,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -791,7 +791,7 @@ private module Parsers
end
def self.parser_name
return {{@type.name}}
return {{ @type.name }}
end
end
end
@ -878,7 +878,7 @@ private module Extractors
end
def self.extractor_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -919,7 +919,7 @@ private module Extractors
end
def self.extractor_name
return {{@type.name}}
return {{ @type.name }}
end
end
@ -953,7 +953,7 @@ private module Extractors
end
def self.extractor_name
return {{@type.name}}
return {{ @type.name }}
end
end
end