You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
The same exception: NoMethodError: undefined methodnested_property' for {:nested_property=>1}}:Hash`
Because Property::Hash itself does not provide methods to deserialise hash into object. But uses feature mechanism to mix-in necessary modules into nested properties. But feature mechanism does work only for nested blocks.
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 thefeature
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:It's nicer to have just one module that should be included and which will do this work. Something like this:
The text was updated successfully, but these errors were encountered: