RubyHash params = (RubyHash)args[0];
if (params.size() < 3) {
throw context.getRuntime().newArgumentError("This method needs at least :lang, :params, and :code keys with values");
}
try {
Var hash_map_fn = DiametricService.getFn("clojure.core", "hash-map");
clojure.lang.PersistentArrayMap clj_map =
(PersistentArrayMap) hash_map_fn.invoke();
Var assoc_fn = DiametricService.getFn("clojure.core", "assoc");
String[] keys = new String[] { "lang", "params", "code", "requires", "imports" };
Class[] valueTypes =
new Class[] { RubySymbol.class, RubyArray.class, RubyString.class, RubyArray.class, RubyArray.class };
for (int i = 0; i < keys.length; i++) {
RubySymbol ruby_key = context.getRuntime().newSymbol(keys[i]);
IRubyObject ruby_value = params.op_aref(context, ruby_key);
if (ruby_value.isNil()) continue;
clj_map = (PersistentArrayMap) assoc_fn.invoke(
clj_map,
DiametricService.keywords.get(ruby_key.toString()),
convertRubyValueToJava(context, ruby_value, valueTypes[i]));
}
RubyClass clazz = (RubyClass) context.getRuntime().getClassFromPath("Diametric::Persistence::Function");
DiametricFunction ruby_function = (DiametricFunction) clazz.allocate();
Var function_fn = DiametricService.getFn("datomic.api", "function");
ruby_function.init((datomic.function.Function) function_fn.invoke(clj_map));
return ruby_function;
} catch (Throwable t) {
throw context.getRuntime().newRuntimeError(t.getMessage());
}
}