- Timestamp:
- 09/11/08 11:10:49 (5 years ago)
- Location:
- lang/ruby/ymldot
- Files:
-
- 1 added
- 8 modified
-
README (modified) (3 diffs)
-
lib/ymldot.rb (modified) (3 diffs)
-
sample/sample.dot (modified) (1 diff)
-
sample/sample.png (modified) (previous)
-
sample/sample.yml (modified) (4 diffs)
-
sample/sample_jp.png (modified) (previous)
-
sample/sample_jp.yml (modified) (4 diffs)
-
spec/test_polymorphic.yml (added)
-
spec/ymldot_spec.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/ymldot/README
r19133 r19163 9 9 == Installation 10 10 (1) if not install graphviz, type following. 11 $ apt-get install graphviz11 $ apt-get install graphviz 12 12 (2) get ymldot. 13 $ gem install ymldot13 $ gem install ymldot 14 14 15 15 == Option … … 32 32 same meaning the relation of ActiveRecord. 33 33 enumerate ref table name. 34 * polymorphic 35 * name 36 * type 37 * tables 38 target table name. 39 34 40 * category 35 41 * label … … 39 45 40 46 == Sample 41 please see "sample/sample.yml" 47 * in file. "sample/sample.yml" 48 49 tables: 50 - name: customer 51 columns: 52 - name 53 - phone_number 54 foreignkeys: 55 has_many: 56 - order 57 - name: order 58 columns: 59 - order_num 60 - name: product 61 columns: 62 - name 63 - amount 64 - tax 65 - product_div 66 foreignkeys: 67 has_many: 68 - order 69 - name: category 70 columns: 71 - name 72 foreignkeys: 73 has_many: 74 - product 75 76 * output dot file. "sample/sample.dot" 77 78 digraph sample { 79 graph[overlap=false, splines=true] 80 81 "category" [shape=record, label="{category|name\l}"] 82 "customer" [shape=record, label="{customer|name\lphone_number\l}"] 83 "order" [shape=record, label="{order|customerID(FK)\lproductID(FK)\lorder_num\l}"] 84 "product" [shape=record, label="{product|categoryID(FK)\lname\lamount\ltax\lproduct_div\l}"] 85 86 "category" -> "product" [arrowtail=none arrowhead=dot headlabel="n" taillabel="1"] 87 "customer" -> "order" [arrowtail=none arrowhead=dot headlabel="n" taillabel="1"] 88 "product" -> "order" [arrowtail=none arrowhead=dot headlabel="n" taillabel="1"] 89 90 } 91 92 * please type 93 $ dot -Tpng sample.dot -o sample.png 42 94 43 95 == Copyright -
lang/ruby/ymldot/lib/ymldot.rb
r19133 r19163 127 127 @config = @node["config"]? @node["config"] : {} 128 128 @category << Tables.new(@node["tables"]) if @node["tables"] and !@node["tables"].empty? 129 @node["category"].each{|c| @category << Tables.new(c["tables"], c["label"], true) } if @node["category"]129 @node["category"].each{|c| @category << Tables.new(c["tables"], c["label"], true) } if @node["category"] 130 130 @category.each{|c| c.entity_dict.each_pair{|k, v| @entity_dict[k] = v}} 131 131 @category.each{|c| c.table_node.each{|e| eval_relation(e) } } … … 139 139 eval_relation_has_one(foreignkeys["has_one"], tname) if foreignkeys["has_one"] 140 140 eval_relation_hmabt(foreignkeys["has_many_and_belongs_to"], tname) if foreignkeys["has_many_and_belongs_to"] 141 eval_relation_polymorphic(foreignkeys["polymorphic"], tname) if foreignkeys["polymorphic"] 141 142 end 142 143 … … 174 175 end 175 176 end 177 178 def eval_relation_polymorphic(keys, tname) 179 keys.each do |rel| 180 @entity_dict[tname].foreignkeys << "#{rel["name"]}ID(FK)" if key = rel["name"] 181 @entity_dict[tname].columns << "#{rel["type"]}(type)" if key = rel["type"] 182 rel["tables"].each do |t| 183 @one_relations << {:self => @entity_dict[t], :have => @entity_dict[tname] } 184 end 185 end 186 end 176 187 end -
lang/ruby/ymldot/sample/sample.dot
r19115 r19163 3 3 4 4 "category" [shape=record, label="{category|name\l}"] 5 "customer" [shape= Mrecord, label="{customer|name\lphone_number\l}"]5 "customer" [shape=record, label="{customer|name\lphone_number\l}"] 6 6 "order" [shape=record, label="{order|customerID(FK)\lproductID(FK)\lorder_num\l}"] 7 7 "product" [shape=record, label="{product|categoryID(FK)\lname\lamount\ltax\lproduct_div\l}"] -
lang/ruby/ymldot/sample/sample.yml
r19115 r19163 1 #2 1 # reference http://codezine.jp/article/detail/154?p=1 3 2 tables: … … 9 8 has_many: 10 9 - order 11 dependent: true12 10 13 11 - name: order 14 12 columns: 15 13 - order_num 16 foreignkeys:17 belongs_to:18 - customer19 - product20 dependent: false21 14 22 15 - name: product … … 27 20 - product_div 28 21 foreignkeys: 29 belongs_to:30 - category31 22 has_many: 32 23 - order 33 dependent: false34 24 35 25 - name: category … … 39 29 has_many: 40 30 - product 41 dependent: false -
lang/ruby/ymldot/sample/sample_jp.yml
r19115 r19163 1 #2 1 # reference http://codezine.jp/article/detail/154?p=1 3 2 config: … … 12 11 has_many: 13 12 - 注文 14 dependent: false15 13 16 14 - name: 注文 17 15 columns: 18 16 - 注文数 19 foreignkeys:20 belongs_to:21 - 顧客22 - 商品23 dependent: false24 17 25 18 - name: 商品 … … 30 23 - 商品区分 31 24 foreignkeys: 32 belongs_to:33 - 商品カテゴリ34 25 has_many: 35 26 - 注文 36 dependent: false37 27 38 28 - name: 商品カテゴリ … … 42 32 has_many: 43 33 - 商品 44 dependent: false45 34 -
lang/ruby/ymldot/spec/ymldot_spec.rb
r19133 r19163 227 227 end 228 228 end 229 230 describe Ymldot, "で読み込んだ.ymlにてpolymorphicを使用した場合" do 231 before do 232 @ymldot = Ymldot.new("test_polymorphic.yml") 233 end 234 235 it "#entity_dict のリレーションが正しいこと" do 236 237 end 238 239 it "#entity_dict['foo'] のforeginkeyは'entiityID(FK)'であること" do 240 @ymldot.entity_dict['foo'].foreignkeys.should be_include 'entityID(FK)' 241 end 242 243 it "#entity_dict['foo'] のcolumnsには'entity_tyep(type)'があること" do 244 @ymldot.entity_dict['foo'].columns.should be_include 'entity_type(type)' 245 end 246 247 it "出力されるdotが正しいこと" do 248 @ymldot.dot_generate.should == <<'EOS' 249 digraph test_polymorphic { 250 graph[overlap=false, splines=true] 251 252 "baf" [shape=record, label="{baf|buge\l}"] 253 "bar" [shape=record, label="{bar|fuge\l}"] 254 "baz" [shape=record, label="{baz|gage\l}"] 255 "foo" [shape=record, label="{foo|entityID(FK)\lhoge\lentity_type(type)\l}"] 256 257 "baf" -> "foo" [arrowtail=none arrowhead=dot headlabel="1" taillabel="1"] 258 "bar" -> "foo" [arrowtail=none arrowhead=dot headlabel="1" taillabel="1"] 259 "baz" -> "foo" [arrowtail=none arrowhead=dot headlabel="1" taillabel="1"] 260 261 } 262 EOS 263 end 264 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)