Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions build/ruby/lib/tucana/shared/shared.data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
8 changes: 8 additions & 0 deletions build/ruby/spec/tucana/shared/shared.data_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down