diff --git a/build/ruby/lib/tucana/shared/shared.data_type.rb b/build/ruby/lib/tucana/shared/shared.data_type.rb index 85e919f..8bdb2e6 100644 --- a/build/ruby/lib/tucana/shared/shared.data_type.rb +++ b/build/ruby/lib/tucana/shared/shared.data_type.rb @@ -26,6 +26,8 @@ def rule_config self.input_types when :return_type self.return_type + when :parent_type + self.parent_type else raise UnexpectedRuleType, "Unknown rule type #{variant}" end @@ -47,6 +49,8 @@ def create(variant, config) self.input_types = DefinitionDataTypeInputTypesRuleConfig.new(config) when :return_type self.return_type = DefinitionDataTypeReturnTypeRuleConfig.new(config) + when :parent_type + self.parent_type = DefinitionDataTypeParentTypeRuleConfig.new(config) else raise UnexpectedRuleType, "Unknown rule type #{variant}" end @@ -159,6 +163,18 @@ def self.from_hash(config) end end + DefinitionDataTypeParentTypeRuleConfig.class_eval do + def to_h + { + parent_type: self.parent_type, + } + end + + def self.from_hash(config) + new(parent_type: DataTypeIdentifier.from_hash(config[:parent_type])) + end + end + DataTypeIdentifier.class_eval do def to_h { diff --git a/build/ruby/spec/tucana/shared/shared.data_type_spec.rb b/build/ruby/spec/tucana/shared/shared.data_type_spec.rb index 511284c..9946064 100644 --- a/build/ruby/spec/tucana/shared/shared.data_type_spec.rb +++ b/build/ruby/spec/tucana/shared/shared.data_type_spec.rb @@ -60,6 +60,14 @@ end end + context "with :parent_type variant" do + it "sets the parent_type field" do + config = { parent_type: { data_type_identifier: "test_type" } } + rule = described_class.create(:parent_type, config) + expect(rule.parent_type).to be_a(Tucana::Shared::DefinitionDataTypeParentTypeRuleConfig) + end + end + context "with unknown variant" do it "raises UnexpectedRuleType error" do expect {