053d5a3320
subrecords
33 lines
1 KiB
Elixir
33 lines
1 KiB
Elixir
defmodule RecycledCloud.OpenNebula.Schema.Records do
|
|
@moduledoc """
|
|
Here we define XSD template into something we can play with (Records).
|
|
|
|
Records are not usually used in elixir except for integrating with erlang
|
|
code - which is what we're doing right now: the records are defined in .hrl
|
|
(erlang headers) by erlsom.
|
|
|
|
See RecycledCloud.OpenNebula.Schema module for details.
|
|
"""
|
|
|
|
require Record
|
|
alias RecycledCloud.OpenNebula.Schema
|
|
|
|
@models %{
|
|
"vm" => Schema.generate_model_for("vm"),
|
|
"vm_pool" => Schema.generate_model_for("vm_pool")
|
|
}
|
|
|
|
def get_model_for(object), do: Map.get(@models, object)
|
|
|
|
extract = fn name, acc -> Record.extract_all(from: Schema.get_hrl_for(name)) ++ acc end
|
|
sources = ["vm", "vm_pool"]
|
|
|> Enum.reduce([], extract)
|
|
|> Enum.sort_by(fn {name, _} -> name end)
|
|
|> Enum.dedup_by(fn {name, _} -> name end)
|
|
|
|
#IO.inspect sources |> Enum.dedup_by(fn {, _} -> name end)
|
|
|
|
for {name, record} <- sources do
|
|
Record.defrecord name, record
|
|
end
|
|
end
|