Sha256: 9ba7ec72e761a3305c9f04391b98d3249f0f045e8a1b36ac72823c6ab7fae1f0
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
require 'zan_tools/generatable' require 'zan_tools/seed' module ZanTools class SpringGenerator include Generatable ID_KEY = 'id' define do def id_type # id类型 fields[ID_KEY]['type'] end def table_name # 表名 name.underscore end def name_for(ext) name + ext end # 填充字段内容 def seeds(ext = {}) conf = {json: true, exclude: [], camel: true}.merge(ext) fs = fields.reject{|k, v| conf[:exclude].include?(k) } if conf[:camel] fs = Hash[fs.map{|k, v| [k.lower_camel, v]}] end ZanTools::Seed.send(conf[:json] ? :generate_json : :generate, fs) end def nonid_fields # 非ID字段 fields.reject{|k, _| k == ID_KEY } end def field(name, conf = {}) fields[name.to_s] = {'type'=>'String'}.merge(Hash[conf.map{|k, v| [k.to_s, v]}]) fields[name.to_s]['type'] = fields[name.to_s]['type'].to_s.upper_camel fields[name.to_s] end end def self.init!(name, fields) configure do |config| config.name = name.upper_camel config.fields = {ID_KEY => {'type'=>'Long'}} fields.each{|name, conf| config.field(name, conf) } end end def self.belongs_to(generator) end def self.has_many(generator) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
zan_tools-0.1.3 | lib/zan_tools/spring_generator.rb |
zan_tools-0.1.2 | lib/zan_tools/spring_generator.rb |
zan_tools-0.1.1 | lib/zan_tools/spring_generator.rb |