So, an update:
I implemented support of json and yaml schemas to generate views dynamically. A schema looks like this:
{
"summary": [
{"name": "id"},
{"name": "active", "alias": "is_active"},
{"name": "full_name", "alias": "name"}
],
"foo": {"name": "foo"}
}
Which is functionally equivalent (it actually generates a view dynamically with the same ruby code) to this:
pane :summary do
field :id
field :active, :is_active
field :full_name, :mario
end
field :foo
And this is how it could be used to generate the views from data:
render json: View.from_json(unparsed_json).new(entity)
render json: View.from_yaml(unparsed_yaml).new(entity)
render json: View.from_hash(data_as_hash).new(entity)
Since those methods generate classes, they can be used to inherit new views, or even doing something like this:
class EAPServerView < View.from_json(:code_to_get_from_hawkular)
end
Also, another important thing is that methods defined inside a view are used for the rendering, so attribute transformation can done in the view, instead of the entity if necessary, like this:
entity = OpenStruct.new(foo: :bar)
class MyView < View
field :foo
def foo
:baz
end
end
Then rendering it would return something like { "foo": "baz" }.
The changes are available on the same repo as always:
github.com/cfcosta/dynamic-entity-poc , and you can find examples on how this work on view_spec.rb, and examples of schemas on spec/fixtures/view_import.*