2020-07-26 14:58:50 +00:00
|
|
|
module DB::Serializable
|
|
|
|
macro included
|
|
|
|
{% verbatim do %}
|
|
|
|
macro finished
|
|
|
|
def self.type_array
|
|
|
|
\{{ @type.instance_vars
|
|
|
|
.reject { |var| var.annotation(::DB::Field) && var.annotation(::DB::Field)[:ignore] }
|
|
|
|
.map { |name| name.stringify }
|
|
|
|
}}
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(tuple)
|
|
|
|
\{% for var in @type.instance_vars %}
|
|
|
|
\{% ann = var.annotation(::DB::Field) %}
|
|
|
|
\{% if ann && ann[:ignore] %}
|
|
|
|
\{% else %}
|
|
|
|
@\{{var.name}} = tuple[:\{{var.name.id}}]
|
|
|
|
\{% end %}
|
|
|
|
\{% end %}
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_a
|
|
|
|
\{{ @type.instance_vars
|
|
|
|
.reject { |var| var.annotation(::DB::Field) && var.annotation(::DB::Field)[:ignore] }
|
|
|
|
.map { |name| name }
|
|
|
|
}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
2019-05-30 23:31:22 +00:00
|
|
|
end
|
2019-04-03 16:35:58 +00:00
|
|
|
end
|
|
|
|
|
2020-07-26 14:58:50 +00:00
|
|
|
module JSON::Serializable
|
|
|
|
macro included
|
|
|
|
{% verbatim do %}
|
|
|
|
macro finished
|
|
|
|
def initialize(tuple)
|
|
|
|
\{% for var in @type.instance_vars %}
|
|
|
|
\{% ann = var.annotation(::JSON::Field) %}
|
|
|
|
\{% if ann && ann[:ignore] %}
|
|
|
|
\{% else %}
|
|
|
|
@\{{var.name}} = tuple[:\{{var.name.id}}]
|
|
|
|
\{% end %}
|
|
|
|
\{% end %}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
2019-05-30 23:31:22 +00:00
|
|
|
end
|
2019-03-28 18:43:40 +00:00
|
|
|
end
|
|
|
|
|
2021-04-17 12:18:58 +00:00
|
|
|
macro templated(filename, template = "template", navbar_search = true)
|
|
|
|
navbar_search = {{navbar_search}}
|
2019-05-30 23:31:22 +00:00
|
|
|
render "src/invidious/views/#{{{filename}}}.ecr", "src/invidious/views/#{{{template}}}.ecr"
|
2018-08-04 20:30:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
macro rendered(filename)
|
2019-05-30 23:31:22 +00:00
|
|
|
render "src/invidious/views/#{{{filename}}}.ecr"
|
2018-08-04 20:30:44 +00:00
|
|
|
end
|