generated from athena-framework/component-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Configuration Annotations (#8)
* Extract Serializable module to its own file * Implement custom configurations annotations * Add `athena-config` as a dependency * Add method on `ASR::Context` to get the direction that context object represents * Bump version
- Loading branch information
1 parent
73a4b94
commit 22164e1
Showing
12 changed files
with
422 additions
and
231 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "../spec_helper" | ||
|
||
ACF.configuration_annotation IsActiveProperty, active : Bool = true | ||
|
||
private struct ActivePropertyExclusionStrategy | ||
include Athena::Serializer::ExclusionStrategies::ExclusionStrategyInterface | ||
|
||
# :inherit: | ||
def skip_property?(metadata : ASR::PropertyMetadataBase, context : ASR::Context) : Bool | ||
return false if context.direction.deserialization? | ||
|
||
ann_configs = metadata.annotation_configurations | ||
|
||
ann_configs.has?(IsActiveProperty) && !ann_configs[IsActiveProperty].active | ||
end | ||
end | ||
|
||
# Mainly testing `Athena::Config` integration in regards to custom annotations accessable via the property metadata. | ||
describe ActivePropertyExclusionStrategy do | ||
describe "#skip_property?" do | ||
describe :deserialization do | ||
it "it should not skip" do | ||
ActivePropertyExclusionStrategy.new.skip_property?(create_metadata, ASR::DeserializationContext.new).should be_false | ||
end | ||
end | ||
|
||
describe :serialization do | ||
describe "without the annotation" do | ||
it "should not skip" do | ||
ActivePropertyExclusionStrategy.new.skip_property?(create_metadata, ASR::SerializationContext.new).should be_false | ||
end | ||
end | ||
|
||
describe "with the annotation" do | ||
it true do | ||
ann_config = ACF::AnnotationConfigurations.new({IsActiveProperty => [IsActivePropertyConfiguration.new] of ACF::AnnotationConfigurations::ConfigurationBase}) | ||
|
||
ActivePropertyExclusionStrategy.new.skip_property?(create_metadata(annotation_configurations: ann_config), ASR::SerializationContext.new).should be_false | ||
end | ||
|
||
it false do | ||
ann_config = ACF::AnnotationConfigurations.new({IsActiveProperty => [IsActivePropertyConfiguration.new(false)] of ACF::AnnotationConfigurations::ConfigurationBase}) | ||
|
||
ActivePropertyExclusionStrategy.new.skip_property?(create_metadata(annotation_configurations: ann_config), ASR::SerializationContext.new).should be_true | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.