diff --git a/lib/literal/properties/schema.rb b/lib/literal/properties/schema.rb index 49dd413..020d6c0 100644 --- a/lib/literal/properties/schema.rb +++ b/lib/literal/properties/schema.rb @@ -94,6 +94,7 @@ def generate_initializer_body [ "@literal_properties = self.class.literal_properties", generate_initializer_handle_properties(@sorted_properties), + "after_initialize if respond_to?(:after_initialize)", ].join("\n") end diff --git a/test/properties.test.rb b/test/properties.test.rb index 874ed81..ea3ce91 100644 --- a/test/properties.test.rb +++ b/test/properties.test.rb @@ -80,3 +80,21 @@ class WithNilableType prop_name = props.first assert(prop_name.optional?) { "Expected name to be optional" } end + +test "after initialize callback" do + callback_called = false + + example = Class.new do + extend Literal::Properties + + prop :name, String + + define_method :after_initialize do + callback_called = true + end + end + + example.new(name: "John") + + assert callback_called +end