class ZanTools::SpringGenerator
Constants
- ID_KEY
Public Class Methods
belongs_to(generator)
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 54 def self.belongs_to(generator) end
has_many(generator)
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 57 def self.has_many(generator) end
init!(name, fields)
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 45 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
Public Instance Methods
field(name, conf = {})
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 38 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
id_type()
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 11 def id_type # id类型 fields[ID_KEY]['type'] end
name_for(ext)
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 19 def name_for(ext) name + ext end
nonid_fields()
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 34 def nonid_fields # 非ID字段 fields.reject{|k, _| k == ID_KEY } end
seeds(ext = {})
click to toggle source
填充字段内容
# File lib/zan_tools/spring_generator.rb, line 24 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
table_name()
click to toggle source
# File lib/zan_tools/spring_generator.rb, line 15 def table_name # 表名 name.underscore end