diff --git a/shard.yml b/shard.yml index e092a23..bb1c298 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: athena-serializer -version: 0.2.2 +version: 0.2.3 crystal: '>= 0.35.0' diff --git a/spec/athena-serializer_spec.cr b/spec/athena-serializer_spec.cr index 64d53eb..a231800 100644 --- a/spec/athena-serializer_spec.cr +++ b/spec/athena-serializer_spec.cr @@ -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 @@ -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 diff --git a/spec/models/virtual_property.cr b/spec/models/virtual_property.cr index 8d7cc99..a0f122e 100644 --- a/spec/models/virtual_property.cr +++ b/spec/models/virtual_property.cr @@ -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 diff --git a/src/serializable.cr b/src/serializable.cr index 985ff65..2e30ec0 100644 --- a/src/serializable.cr +++ b/src/serializable.cr @@ -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 %}