-
-
Save paulcsmith/7973eae4f6fa5584e7e26f4163d3b026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here is what I have now | |
def self.create{% if with_bang %}!{% end %}( | |
{% if with_params %}params,{% end %} | |
{% for type_declaration in (NEEDS_ON_CREATE + NEEDS_ON_INITIALIZE) %} | |
{{ type_declaration }}, | |
{% end %} | |
{% if @type.constant :FIELDS %} | |
{% for field in FIELDS %} | |
{{ field[:name] }} : {{ field[:type] }} | Nothing{% if field[:nilable] %} | Nil{% end %} = Nothing.new, | |
{% end %} | |
{% end %} | |
{% for field in VIRTUAL_FIELDS %} | |
{{ field.var }} : {{ field.type }} | Nothing = Nothing.new, | |
{% end %} | |
) | |
# Here's what I'd *love* to do | |
def self.create{% if with_bang %}!{% end %}( | |
{% if with_params %}params,{% end %} | |
{{ args_for_needs() }} | |
{{ args_for_fields() }} | |
{{ args_for_virtual_fields() }} | |
# Or maybe a method like this | |
{{ run_macro args_for_fields() }} | |
) | |
macro args_for_needs | |
{% for type_declaration in (NEEDS_ON_CREATE + NEEDS_ON_INITIALIZE) %} | |
{{ type_declaration }}, | |
{% end %} | |
end | |
macro args_for_fields | |
{% if @type.constant :FIELDS %} | |
{% for field in FIELDS %} | |
{{ field[:name] }} : {{ field[:type] }} | Nothing{% if field[:nilable] %} | Nil{% end %} = Nothing.new, | |
{% end %} | |
{% end %} | |
end | |
macro args_for_virtual_fields | |
{% for field in VIRTUAL_FIELDS %} | |
{{ field.var }} : {{ field.type }} | Nothing = Nothing.new, | |
{% end %} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment