Skip to content

Commit d271f64

Browse files
committed
spaces around macro expression
1 parent 941496e commit d271f64

28 files changed

+324
-324
lines changed

spec/sql/select/join_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module JoinSpec
2323
it "constructs all common type of joins" do
2424
# Just ensure it is callable.
2525
{% for join in [:left, :inner, :right, :full_outer, :cross] %}
26-
Lustra::SQL.select.from("posts").{{join.id}}_join("users")
26+
Lustra::SQL.select.from("posts").{{ join.id }}_join("users")
2727
{% end %}
2828
end
2929

src/lustra/cli/generator.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Lustra::CLI::Generator < Admiral::Command
2727
end
2828

2929
macro ecr_to_s(string, opts)
30-
opts = {{opts}}
30+
opts = {{ opts }}
3131
io = IO::Memory.new
32-
ECR.embed {{string}}, io
32+
ECR.embed {{ string }}, io
3333
io.to_s
3434
end
3535
end

src/lustra/expression/expression.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ class Lustra::Expression
345345
# Used internally by the expression engine.
346346
macro method_missing(call)
347347
{% if call.args.size > 0 %}
348-
args = {{call.args}}.map { |x| Lustra::Expression[x] }
349-
return Node::Function.new("{{call.name.id}}", args)
348+
args = {{ call.args }}.map { |x| Lustra::Expression[x] }
349+
return Node::Function.new("{{ call.name.id }}", args)
350350
{% else %}
351-
return Node::Variable.new({{call.name.id.stringify}})
351+
return Node::Variable.new({{ call.name.id.stringify }})
352352
{% end %}
353353
end
354354
end

src/lustra/expression/nodes/node.cr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ require "../expression"
33
# Mother class of all the rendering nodes
44
abstract class Lustra::Expression::Node
55
macro define_operator(op_name, sql_name, null = false)
6-
def {{op_name.id}}(any : Node) : Node
7-
Node::DoubleOperator.new(self, any, "{{sql_name.id}}")
6+
def {{ op_name.id }}(any : Node) : Node
7+
Node::DoubleOperator.new(self, any, "{{ sql_name.id }}")
88
end
99

1010
{% if null %}
11-
def {{op_name.id}}(some_nil : Nil) : Node
12-
Node::DoubleOperator.new(self, Null.new, {{null}} )
11+
def {{ op_name.id }}(some_nil : Nil) : Node
12+
Node::DoubleOperator.new(self, Null.new, {{ null }} )
1313
end
1414
{% end %}
1515

16-
def {{op_name.id}}(any : T) : Node forall T
17-
Node::DoubleOperator.new(self, Literal.new(any), "{{sql_name.id}}")
16+
def {{ op_name.id }}(any : T) : Node forall T
17+
Node::DoubleOperator.new(self, Literal.new(any), "{{ sql_name.id }}")
1818
end
1919
end
2020

2121
{% for op in [">", ">=", "<", "<=", "+", "-", "*", "/"] %}
22-
define_operator({{op}}, {{op}})
22+
define_operator({{ op }}, {{ op }})
2323
{% end %}
2424

2525
def =~(any : Node) : Node

src/lustra/expression/nodes/variable.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class Lustra::Expression::Node::Variable < Lustra::Expression::Node
1818

1919
macro method_missing(call)
2020
{% if call.args.size > 0 %}
21-
args = Lustra::Expression[{{call.args}}].join(", ")
22-
return Node::Variable.new("{{call.name.id}}(#{args})", self)
21+
args = Lustra::Expression[{{ call.args }}].join(", ")
22+
return Node::Variable.new("{{ call.name.id }}(#{args})", self)
2323
{% else %}
24-
return Node::Variable.new({{call.name.id.stringify}}, self)
24+
return Node::Variable.new({{ call.name.id.stringify }}, self)
2525
{% end %}
2626
end
2727

src/lustra/extensions/enum/enum.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ module Lustra
111111
# u.gender = MyApp::Gender::Male
112112
# ```
113113
macro enum(name, *values, &block)
114-
struct {{name.id}} < ::Lustra::Enum
114+
struct {{ name.id }} < ::Lustra::Enum
115115
{% for i in values %}
116-
{{i.camelcase.id}} = {{name.id}}.new("{{i.id}}")
116+
{{ i.camelcase.id }} = {{ name.id }}.new("{{ i.id }}")
117117
{% end %}
118118

119119
{% begin %}
120120
AUTHORIZED_VALUES = {
121121
{% for i in values %}
122-
"{{i.id}}" => {{i.camelcase.id}},
122+
"{{ i.id }}" => {{ i.camelcase.id }},
123123
{% end %}
124124
}
125125
{% end %}
@@ -168,7 +168,7 @@ module Lustra
168168
Lustra::Model::Converter.add_converter("\{{@type}}", ::Lustra::Model::Converter::\{{@type}}Converter)
169169
end
170170

171-
{{yield}}
171+
{{ yield }}
172172
end
173173
end
174174
end

src/lustra/extensions/full_text_searchable/model.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ require "./tsvector"
8787
module Lustra::Model::FullTextSearchable
8888
# Set this model as searchable using tsvector
8989
macro full_text_searchable(through = "full_text_vector", catalog = "pg_catalog.english", scope_name = "search")
90-
column( {{through.id}} : Lustra::TSVector, presence: false)
90+
column( {{ through.id }} : Lustra::TSVector, presence: false)
9191

92-
scope "{{scope_name.id}}" do |str|
92+
scope "{{ scope_name.id }}" do |str|
9393
table = self.item_class.table
9494
where {
9595
op(
96-
var(table, "{{through.id}}"),
97-
to_tsquery({{catalog}}, Lustra::Model::FullTextSearchable.to_tsq(str)),
96+
var(table, "{{ through.id }}"),
97+
to_tsquery({{ catalog }}, Lustra::Model::FullTextSearchable.to_tsq(str)),
9898
"@@"
9999
)
100100
}

src/lustra/model/collection.cr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,9 @@ module Lustra::Model
769769
end
770770

771771
{% for j in ["left", "right", "full_outer", "inner"] %}
772-
# {{j.id.upcase}} JOIN using association name (auto-detects join conditions)
773-
def {{j.id}}_join(association : Lustra::SQL::Symbolic, lateral = false)
774-
auto_join_association(association, :{{j.id}}, lateral)
772+
# {{ j.id.upcase }} JOIN using association name (auto-detects join conditions)
773+
def {{ j.id }}_join(association : Lustra::SQL::Symbolic, lateral = false)
774+
auto_join_association(association, :{{ j.id }}, lateral)
775775
end
776776
{% end %}
777777

@@ -780,21 +780,21 @@ module Lustra::Model
780780
{% begin %}
781781
case association.to_s
782782
{% for name, settings in T::RELATIONS %}
783-
when "{{name}}"
783+
when "{{ name }}"
784784
{% if settings[:relation_type] == :has_many %}
785785
# has_many :posts => posts.user_id = users.id
786786
%foreign_key =
787787
{% if settings[:foreign_key] %}
788-
"{{settings[:foreign_key]}}"
788+
"{{ settings[:foreign_key] }}"
789789
{% else %}
790790
T.table.to_s.singularize + "_id"
791791
{% end %}
792792

793-
%relation_table = {{settings[:type]}}.table
793+
%relation_table = {{ settings[:type] }}.table
794794

795795
%primary_key =
796796
{% if settings[:primary_key] %}
797-
"{{settings[:primary_key]}}"
797+
"{{ settings[:primary_key] }}"
798798
{% else %}
799799
T.__pkey__
800800
{% end %}
@@ -805,17 +805,17 @@ module Lustra::Model
805805
# has_one :info => user_infos.user_id = users.id
806806
%foreign_key =
807807
{% if settings[:foreign_key] %}
808-
"{{settings[:foreign_key]}}"
808+
"{{ settings[:foreign_key] }}"
809809
{% else %}
810810
T.table.to_s.singularize + "_id"
811811
{% end %}
812812

813813
# Get the table name from the type (handling nilable like UserInfo?)
814-
%relation_table = {{settings[:type].stringify.gsub(/\s*\|\s*Nil/, "").gsub(/\s*\|\s*::Nil/, "").id}}.table
814+
%relation_table = {{ settings[:type].stringify.gsub(/\s*\|\s*Nil/, "").gsub(/\s*\|\s*::Nil/, "").id }}.table
815815

816816
%primary_key =
817817
{% if settings[:primary_key] %}
818-
"{{settings[:primary_key]}}"
818+
"{{ settings[:primary_key] }}"
819819
{% else %}
820820
T.__pkey__
821821
{% end %}
@@ -826,13 +826,13 @@ module Lustra::Model
826826
# belongs_to :user => posts.user_id = users.id
827827
%foreign_key =
828828
{% if settings[:foreign_key] %}
829-
"{{settings[:foreign_key]}}"
829+
"{{ settings[:foreign_key] }}"
830830
{% else %}
831-
"{{name}}_id"
831+
"{{ name }}_id"
832832
{% end %}
833833

834-
%relation_table = {{settings[:type]}}.table
835-
%primary_key = {{settings[:type]}}.__pkey__
834+
%relation_table = {{ settings[:type] }}.table
835+
%primary_key = {{ settings[:type] }}.__pkey__
836836

837837
condition = "#{Lustra::SQL.escape(T.table)}.#{Lustra::SQL.escape(%foreign_key)} = #{Lustra::SQL.escape(%relation_table)}.#{Lustra::SQL.escape(%primary_key)}"
838838
join(Lustra::SQL.escape(%relation_table), type, condition, lateral)
@@ -842,24 +842,24 @@ module Lustra::Model
842842
# 1. JOIN posts ON posts.user_id = users.id
843843
# 2. JOIN categories ON posts.category_id = categories.id
844844

845-
%through_table = {{settings[:through]}}.table
845+
%through_table = {{ settings[:through] }}.table
846846

847847
%own_key =
848848
{% if settings[:own_key] %}
849-
"{{settings[:own_key]}}"
849+
"{{ settings[:own_key] }}"
850850
{% else %}
851851
T.table.to_s.singularize + "_id"
852852
{% end %}
853853

854854
%through_key =
855855
{% if settings[:foreign_key] %}
856-
"{{settings[:foreign_key]}}"
856+
"{{ settings[:foreign_key] }}"
857857
{% else %}
858-
{{settings[:type]}}.table.to_s.singularize + "_id"
858+
{{ settings[:type] }}.table.to_s.singularize + "_id"
859859
{% end %}
860860

861-
%final_table = {{settings[:type]}}.table
862-
%final_pkey = {{settings[:type]}}.__pkey__
861+
%final_table = {{ settings[:type] }}.table
862+
%final_pkey = {{ settings[:type] }}.__pkey__
863863

864864
# First join: through table
865865
through_condition = "#{Lustra::SQL.escape(%through_table)}.#{Lustra::SQL.escape(%own_key)} = #{Lustra::SQL.escape(T.table)}.#{Lustra::SQL.escape(T.__pkey__)}"

src/lustra/model/converters/array_converter.cr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ ARRAY_TYPEMAP = {
1919
}
2020

2121
{% for k, exp in ARRAY_VALUES %}
22-
module Lustra::Model::Converter::ArrayConverter{{exp.id}}
23-
def self.to_column(x) : Array(::{{exp.id}})?
22+
module Lustra::Model::Converter::ArrayConverter{{ exp.id }}
23+
def self.to_column(x) : Array(::{{ exp.id }})?
2424
case x
2525
when Nil
2626
nil
27-
when ::{{exp.id}}
27+
when ::{{ exp.id }}
2828
[x]
29-
when Array(::{{exp.id}})
29+
when Array(::{{ exp.id }})
3030
x
31-
when Array(::PG::{{exp.id}}Array)
31+
when Array(::PG::{{ exp.id }}Array)
3232
x.map do |i|
3333
case i
34-
when ::{{exp.id}}
34+
when ::{{ exp.id }}
3535
i
3636
else
3737
nil
3838
end
3939
end.compact
4040
when Array(::JSON::Any)
41-
x.map(&.as_{{k.id}})
41+
x.map(&.as_{{ k.id }})
4242
when ::JSON::Any
4343
if arr = x.as_a?
44-
arr.map(&.as_{{k.id}})
44+
arr.map(&.as_{{ k.id }})
4545
else
46-
raise "Cannot convert from #{x.class} to Array({{exp.id}}) [1]"
46+
raise "Cannot convert from #{x.class} to Array({{ exp.id }}) [1]"
4747
end
4848
else
49-
raise "Cannot convert from #{x.class} to Array({{exp.id}}) [2]"
49+
raise "Cannot convert from #{x.class} to Array({{ exp.id }}) [2]"
5050
end
5151
end
5252

@@ -59,15 +59,15 @@ ARRAY_TYPEMAP = {
5959
end
6060
end
6161

62-
def self.to_db(x : Array(::{{exp.id}})?) : Lustra::SQL::Any
62+
def self.to_db(x : Array(::{{ exp.id }})?) : Lustra::SQL::Any
6363
{% t = ARRAY_TYPEMAP["#{exp.id}"] %}
6464

6565
return unless x
6666

67-
Lustra::Expression.unsafe({"Array[", to_string(x), "]::{{t.id}}"}.join)
67+
Lustra::Expression.unsafe({"Array[", to_string(x), "]::{{ t.id }}"}.join)
6868
end
6969
end
7070

71-
Lustra::Model::Converter.add_converter("Array({{exp.id}})", Lustra::Model::Converter::ArrayConverter{{exp.id}})
72-
Lustra::Model::Converter.add_converter("Array({{exp.id}} | Nil)", Lustra::Model::Converter::ArrayConverter{{exp.id}})
71+
Lustra::Model::Converter.add_converter("Array({{ exp.id }})", Lustra::Model::Converter::ArrayConverter{{ exp.id }})
72+
Lustra::Model::Converter.add_converter("Array({{ exp.id }} | Nil)", Lustra::Model::Converter::ArrayConverter{{ exp.id }})
7373
{% end %}

src/lustra/model/converters/base.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Lustra::Model::Converter
2020
{% raise "Unknown converter: #{name}" %}
2121
{% end %}
2222

23-
{{ CONVERTERS[name] }}.to_column({{value}})
23+
{{ CONVERTERS[name] }}.to_column({{ value }})
2424
end
2525

2626
macro to_db(name, value)
@@ -32,6 +32,6 @@ module Lustra::Model::Converter
3232
{% raise "Unknown converter: #{name}" %}
3333
{% end %}
3434

35-
{{ CONVERTERS[name] }}.to_db({{value}})
35+
{{ CONVERTERS[name] }}.to_db({{ value }})
3636
end
3737
end

0 commit comments

Comments
 (0)