-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inheritance in format (e.g. xml do
) specific blocks
#7
Comments
@ronaldtse In some cases we can use modules to share code: module BibliographicItem
def self.included(base)
base.class_eval do
attribute :schema_version, Shale::Type::String
...
xml do
map_attribute "schema-version", to: :schema_version
...
end
end
end
end
class Bibitem < Shale::Mapper
include BibliographicItem
@xml_mapping.instance_eval do
root "bibitem"
...
end
end
class Bibdata < Shale::Mapper
include BibliographicItem
@xml_mapping.instance_eval do
root "bibdata"
...
end
end |
This is a pain for me as well, and I have already been yelling at the clown set up of this software. Repeating all accessors every time we inherit a class defeats the entire point of using classes to define accessors to XML and YAML. |
For @opoudjis it’s even more painful because he needs to override only one element in a tree of Mapper classes, and it forces him to inherit the entire tree of classes but only override one. |
But can you design a syntax that address this? We can then find a way to implement it. |
The most obvious thing to do would be to treat the do block like a class method (even if it isn't one), and introduce So:
The other thing to do would be to modularise mappings in the XML block into class methods, which could then be overridden:
|
Shale provides format specific blocks such as:
When a class inherits from it, the
xml
block mapping is completely wiped:It is very inconvenient to have to re-specify all format-specific mappings.
This situation is terrible for versioned namespaces because let's say there is UML version 2013 vs version 2016, the objects are slightly different, but the entire format block really needs to get rewritten.
Here's an example of the ideal situation:
The correct situation is to have format specific mappings retained unless overridden. There could also be a command that removes all mappings should that be necessary, such as
xml! do
.The text was updated successfully, but these errors were encountered: