Class: StatefulEnum::PlantUML::UmlWriter
- Inherits:
-
Object
- Object
- StatefulEnum::PlantUML::UmlWriter
- Defined in:
- lib/generators/stateful_enum/plantuml_generator.rb
Instance Method Summary collapse
- #event(name, &block) ⇒ Object
-
#initialize(model, column, states, prefix, suffix, &block) ⇒ UmlWriter
constructor
A new instance of UmlWriter.
Constructor Details
#initialize(model, column, states, prefix, suffix, &block) ⇒ UmlWriter
Returns a new instance of UmlWriter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/stateful_enum/plantuml_generator.rb', line 23 def initialize(model, column, states, prefix, suffix, &block) @states, @prefix, @suffix = states, prefix, suffix @items = [] if (default_value = model.columns_hash[column.to_s].default) default_label = model.defined_enums[column.to_s].key default_value.to_i # SQLite returns the default value in String end instance_eval(&block) lines = default_label ? ["[*] --> #{default_label}"] : [] lines.concat @items.map {|item| "#{item.from} --> #{item.to} :#{item.label}" } (@items.map(&:to).uniq - @items.map(&:from).uniq).each do |final| lines.push "#{final} --> [*]" end File.write(File.join((ENV['DEST_DIR'] || Dir.pwd), "#{model.name}.puml"), lines.join("\n") << "\n") end |
Instance Method Details
#event(name, &block) ⇒ Object
42 43 44 |
# File 'lib/generators/stateful_enum/plantuml_generator.rb', line 42 def event(name, &block) EventStore.new @items, @states, @prefix, @suffix, name, &block end |