Skip to content

Commit

Permalink
Model generation
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNicollet committed Jan 11, 2013
1 parent fa4f9a7 commit a22e04e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tool/snip.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,55 @@ let put list = List.iter (fun (file,contents) ->
print_endline (">> " ^ file)
) list

(* Actual generation ---------------------------------------------------------------------- *)

let id name = put [
ml name, "include Ohm.Id.Phantom\n" ;
mli name, "include Ohm.Id.PHANTOM\n" ;
]

let model name =
let short = BatString.lchop name in
id ("I" ^ short) ;
put [

ml name, Printf.sprintf "open Ohm
open Ohm.Universal
module Data = struct
module T = struct
type json t = {
}
end
include T
include Fmt.Extend(T)
end
include CouchDB.Convenience.Table
(struct let db = O.db %S end)(I%s)(Data)
"
(String.lowercase short) (* DB name *)
short ;

mli name, Printf.sprintf "module Data : sig
type t = {
}
end
module Tbl : Ohm.CouchDB.TABLE
with type elt = Data.t
and type id = I%s.t
module Design : Ohm.CouchDB.DESIGN
"
short
]

(* Entry pointration ---------------------------------------------------------------------- *)

let one = function
| name when name -- "I[A-Za-z0-9]*" -> id name
| name when name -- "M[A-Za-z0-9]*" -> model name
| name -> print_endline (Printf.sprintf "Don't know what to do with %S" name)

let make args = List.iter one args

0 comments on commit a22e04e

Please sign in to comment.