Skip to content

Commit 63c63e9

Browse files
committed
Add parent_type rule for ruby methods
1 parent 0813fd6 commit 63c63e9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

build/ruby/lib/tucana/shared/shared.data_type.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def rule_config
2626
self.input_types
2727
when :return_type
2828
self.return_type
29+
when :parent_type
30+
self.parent_type
2931
else
3032
raise UnexpectedRuleType, "Unknown rule type #{variant}"
3133
end
@@ -47,6 +49,8 @@ def create(variant, config)
4749
self.input_types = DefinitionDataTypeInputTypesRuleConfig.new(config)
4850
when :return_type
4951
self.return_type = DefinitionDataTypeReturnTypeRuleConfig.new(config)
52+
when :parent_type
53+
self.parent_type = DefinitionDataTypeParentTypeRuleConfig.new(config)
5054
else
5155
raise UnexpectedRuleType, "Unknown rule type #{variant}"
5256
end
@@ -159,6 +163,18 @@ def self.from_hash(config)
159163
end
160164
end
161165

166+
DefinitionDataTypeParentTypeRuleConfig.class_eval do
167+
def to_h
168+
{
169+
parent_type: self.parent_type,
170+
}
171+
end
172+
173+
def self.from_hash(config)
174+
new(parent_type: DataTypeIdentifier.from_hash(config[:parent_type]))
175+
end
176+
end
177+
162178
DataTypeIdentifier.class_eval do
163179
def to_h
164180
{

build/ruby/spec/tucana/shared/shared.data_type_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
end
6161
end
6262

63+
context "with :parent_type variant" do
64+
it "sets the parent_type field" do
65+
config = { parent_type: { data_type_identifier: "test_type" } }
66+
rule = described_class.create(:parent_type, config)
67+
expect(rule.parent_type).to be_a(Tucana::Shared::DefinitionDataTypeParentTypeRuleConfig)
68+
end
69+
end
70+
6371
context "with unknown variant" do
6472
it "raises UnexpectedRuleType error" do
6573
expect {

0 commit comments

Comments
 (0)