-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Model = Struct.new(:content)
class Nested < Disposable::Twin
property :nested_property
end
class Outer < Disposable::Twin
include Property::Hash
property :content, field: hash, twin: Nested
end
Outer.new(Model.new({nested_property: 1})) # will fail with message:
# NoMethodError: undefined method `nested_property' for {:nested_property=>1}}:Hash
The reason of failing is that the Property::Hash module includes the following three modules (NestedDefaults, Property::Struct, Hash::Sync) in the nested class by means of the feature mechanism which works only for nested fields defined in the block but not in the separate class.
Since this feature behaviour seems to be correct (in general modules should be explicitly included in the classes) I can see two possible ways to solve an issue:
- use another dedicated way to include these specific modules into the nested class (in this particular case I see it to be appropriated)
- explicitly include these modules in the nested class. For now it is just a workaround which uses undocumented functions. In order to become a solution it should be documented and preserved from the unannounced changes but actually it looks ugly:
class Nested < Disposable::Twin
feature Disposable::Twin::Property::Hash::NestedDefaults
feature Disposable::Twin::Property::Struct
feature Disposable::Twin::Property::Hash::Sync
property :nested_property
end
It's nicer to have just one module that should be included and which will do this work. Something like this:
class Nested < Disposable::Twin
feature Disposable::Twin::Property::Hashable
property :nested_property
end
Metadata
Metadata
Assignees
Labels
No labels