ymldot 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/ymldot +1 -1
  2. data/lib/ymldot.rb +25 -16
  3. metadata +4 -4
data/bin/ymldot CHANGED
@@ -9,7 +9,7 @@ end
9
9
  require 'ymldot'
10
10
  require 'optparse'
11
11
 
12
- Version = "0.0.5"
12
+ Version = "0.0.6"
13
13
  is_output = false
14
14
  is_csv = false
15
15
  opt = OptionParser.new
data/lib/ymldot.rb CHANGED
@@ -67,6 +67,10 @@ class Tables
67
67
  res
68
68
  end
69
69
 
70
+ def add_entity(table)
71
+ eval_entity(table)
72
+ end
73
+
70
74
  private
71
75
  def eval_entity(table)
72
76
  columns = table["columns"]; columns ||= []
@@ -128,8 +132,14 @@ EOS
128
132
  if @config["size"] && @config["size"]["x"] && @config["size"]["y"]
129
133
  res << %Q!graph [size="#{(@config["size"]["x"]/2.54).round},#{(@config["size"]["y"]/2.54).round}"]\n!
130
134
  end
131
- raise "Error: please seto 'font'" if @config["ja"] && @config["font"]
132
- res << %Q!node [fontname="#{@config["font"]}"]! if @config["font"]
135
+ raise "Error: please set 'font'" if @config["ja"] && @config["font"]
136
+
137
+ if @config["font"] || @config["fontsize"]
138
+ res << "node ["
139
+ res << %Q!fontname="#{@config["font"]}"! if @config["font"]
140
+ res << %Q!, fontsize=#{@config["fontsize"]}! if @config["fontsize"]
141
+ res << "]"
142
+ end
133
143
  res
134
144
  end
135
145
 
@@ -165,16 +175,16 @@ EOS
165
175
  @category << Tables.new(@node["tables"]) if @node["tables"] and !@node["tables"].empty?
166
176
  @node["category"].each{|c| @category << Tables.new(c["tables"], c["label"], true) } if @node["category"]
167
177
  @category.each{|c| c.entity_dict.each_pair{|k, v| @entity_dict[k] = v}}
168
- @category.each{|c| c.table_node.each{|e| eval_relation(e) } }
178
+ @category.each{|c| c.table_node.each{|e| eval_relation(e, c) } }
169
179
  end
170
180
 
171
- def eval_relation(table)
181
+ def eval_relation(table, category)
172
182
  foreignkeys = table["foreignkeys"]
173
183
  tname = table["name"]
174
184
  return unless foreignkeys
175
185
  eval_relation_has_many(foreignkeys["has_many"], tname) if foreignkeys["has_many"]
176
186
  eval_relation_has_one(foreignkeys["has_one"], tname) if foreignkeys["has_one"]
177
- eval_relation_hmabt(foreignkeys["has_many_and_belongs_to"], tname) if foreignkeys["has_many_and_belongs_to"]
187
+ eval_relation_habtm(foreignkeys["has_and_belongs_to_many"], tname, category) if foreignkeys["has_and_belongs_to_many"]
178
188
  eval_relation_polymorphic(foreignkeys["polymorphic"], tname) if foreignkeys["polymorphic"]
179
189
  end
180
190
 
@@ -194,23 +204,22 @@ EOS
194
204
  end
195
205
  end
196
206
 
197
- def eval_relation_hmabt(keys, tname)
207
+ def eval_relation_habtm(keys, tname, category)
198
208
  keys.each do |rel|
199
- join_tname = "#{rel}_#{tname}"
200
- return if @entity_dict.has_key? join_tname
201
- join_tname = "#{tname}_#{rel}"
202
- @entity_dict[join_tname] ||= Entity.new(join_tname, true)
203
- @entity_dict[join_tname].foreignkeys << append_fk_str(singularize(tname))
204
- @entity_dict[join_tname].foreignkeys << append_fk_str(singularize(rel))
209
+ join_tname = [rel, tname].sort.join("_")
210
+ return if category.entity_dict.has_key? join_tname
205
211
 
206
212
  # make new category
207
213
  keys = []
208
214
  keys << append_fk_str(tname)
209
215
  keys << append_fk_str(rel)
210
- @category << Tables.new([{"name" => join_tname, "columns" => keys}])
211
-
212
- @many_relations << {:self => @entity_dict[tname], :have => @entity_dict[join_tname]}
213
- @many_relations << {:self => @entity_dict[rel], :have => @entity_dict[join_tname]}
216
+
217
+ category.add_entity("name" => join_tname)
218
+ category.entity_dict[join_tname].foreignkeys << append_fk_str(singularize(tname))
219
+ category.entity_dict[join_tname].foreignkeys << append_fk_str(singularize(rel))
220
+
221
+ @many_relations << {:self => category.entity_dict[tname], :have => category.entity_dict[join_tname]}
222
+ @many_relations << {:self => category.entity_dict[rel], :have => category.entity_dict[join_tname]}
214
223
  end
215
224
  end
216
225
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ymldot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nari
@@ -13,10 +13,10 @@ date: 2008-10-22 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: ""
16
+ description: Can describe ERD in a from of ".yml"
17
17
  email: authornari@gmail.com
18
- executables: []
19
-
18
+ executables:
19
+ - ymldot
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files: []