Skip to content

Commit

Permalink
Allow applying since/until and groups annotation to virtual properties (
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Jan 20, 2021
1 parent 1020375 commit d628151
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: athena-serializer

version: 0.2.2
version: 0.2.3

crystal: '>= 0.35.0'

Expand Down
20 changes: 19 additions & 1 deletion spec/athena-serializer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,14 @@ describe ASR::Serializable do
describe ASRA::VirtualProperty do
it "should only return properties that are not excluded" do
properties = VirtualProperty.new.serialization_properties
properties.size.should eq 2
properties.size.should eq 3

p = properties[0]

p.name.should eq "foo"
p.groups.should eq ["default"]
p.since_version.should be_nil
p.until_version.should be_nil
p.external_name.should eq "foo"
p.value.should eq "foo"
p.skip_when_empty?.should be_false
Expand All @@ -437,11 +440,26 @@ describe ASR::Serializable do
p = properties[1]

p.name.should eq "get_val"
p.groups.should eq ["default"]
p.since_version.should be_nil
p.until_version.should be_nil
p.external_name.should eq "get_val"
p.value.should eq "VAL"
p.skip_when_empty?.should be_false
p.type.should eq String
p.class.should eq VirtualProperty

p = properties[2]

p.name.should eq "group_version"
p.groups.should eq ["group1"]
p.since_version.should eq SemanticVersion.parse "1.3.2"
p.until_version.should eq SemanticVersion.parse "1.2.3"
p.external_name.should eq "group_version"
p.value.should eq "group_version"
p.skip_when_empty?.should be_false
p.type.should eq String
p.class.should eq VirtualProperty
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/models/virtual_property.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ class VirtualProperty
def get_val : String
"VAL"
end

@[ASRA::VirtualProperty]
@[ASRA::Groups("group1")]
@[ASRA::Since("1.3.2")]
@[ASRA::Until("1.2.3")]
def group_version : String
"group_version"
end
end
3 changes: 3 additions & 0 deletions src/serializable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ module Athena::Serializer::Serializable
annotation_configurations: ACF::AnnotationConfigurations.new(#{method_annotation_configurations} of ACF::AnnotationConfigurations::Classes => Array(ACF::AnnotationConfigurations::ConfigurationBase)),
value: #{m.name.id},
skip_when_empty: #{!!m.annotation(ASRA::SkipWhenEmpty)},
groups: #{(ann = m.annotation(ASRA::Groups)) && !ann.args.empty? ? [ann.args.splat] : ["default"]},
since_version: #{(ann = m.annotation(ASRA::Since)) && !ann[0].nil? ? "SemanticVersion.parse(#{ann[0]})".id : nil},
until_version: #{(ann = m.annotation(ASRA::Until)) && !ann[0].nil? ? "SemanticVersion.parse(#{ann[0]})".id : nil},
)).id %}
{% end %}

Expand Down

0 comments on commit d628151

Please sign in to comment.