Skip to content

Commit 22dfda9

Browse files
authored
Merge pull request #4 from imdrasil/fix_jennifer_association_macro
Fix broken jennifer association macro
2 parents d58ad5d + d870605 commit 22dfda9

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

shard.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: factory
2-
version: 0.1.2
2+
version: 0.1.3
33

44
authors:
55
- Roman Kalnytskyi <moranibaca@gmail.com>
@@ -9,8 +9,8 @@ crystal: 0.24.1
99
license: MIT
1010
development_dependencies:
1111
minitest:
12-
github: ysbaddaden/minitest.cr
13-
version: "~> 0.3.6"
12+
github: ysbaddaden/minitest.cr
13+
version: "~> 0.4.0"
1414
# TODO: uncomment after resolving issue with migrating jennifer to 0.24.1 crystal
1515
# jennifer:
1616
# github: imdrasil/jennifer.cr

src/factory/jennifer/base.cr

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@ module Factory
22
module Jennifer
33
macro association_macro
44
macro association(name, factory = nil, strategy = :create, options = nil)
5-
\{% ASSOCIATIONS << name.id.stringify %}
6-
7-
\{% if factory %}
8-
\{% klass = factory %}
9-
\{% else %}
10-
\{% klass = (name.id.stringify.camelcase + "Factory" ).id%}
11-
\{% end %}
12-
13-
def self.__process_association_\{{name.id}}(obj)
14-
aobj = \{{klass}}.build(\{% if options %}\{{options}} \{% end %})
15-
\{% if strategy.id.stringify == "build" %}
16-
obj.append_\{{name.id}}(aobj)
17-
\{% elsif strategy.id.stringify == "create" %}
18-
obj.add_\{{name.id}}(aobj)
19-
\{% else %}
20-
\{% raise "Strategy #{strategy.id} of #{@type} is not valid"}
21-
\{% end %}
22-
end
5+
{% verbatim do %}
6+
{% ASSOCIATIONS << name.id.stringify %}
7+
8+
{% if factory %}
9+
{% klass = factory %}
10+
{% else %}
11+
{% klass = (name.id.stringify.camelcase + "Factory" ).id%}
12+
{% end %}
13+
14+
def self.__process_association_\{{name.id}}(obj)
15+
aobj = {{klass}}.build({% if options %}{{options}} {% end %})
16+
{% if strategy.id.stringify == "build" %}
17+
obj.append_{{name.id}}(aobj)
18+
{% elsif strategy.id.stringify == "create" %}
19+
obj.add_{{name.id}}(aobj)
20+
{% else %}
21+
{% raise "Strategy #{strategy.id} of #{@type} is not valid" %}
22+
{% end %}
23+
end
24+
{% end %}
2325
end
2426
end
2527

0 commit comments

Comments
 (0)