Class: AttributeBuilder
- Inherits:
-
Object
- Object
- AttributeBuilder
- Defined in:
- lib/kody/builder/attribute_builder.rb
Instance Attribute Summary collapse
-
#imports ⇒ Object
readonly
Returns the value of attribute imports.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(attribute, class_builder, engine) ⇒ AttributeBuilder
constructor
A new instance of AttributeBuilder.
- #to_liquid ⇒ Object
Constructor Details
#initialize(attribute, class_builder, engine) ⇒ AttributeBuilder
Returns a new instance of AttributeBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kody/builder/attribute_builder.rb', line 8 def initialize(attribute, class_builder, engine) @attribute = attribute @engine = engine @imports = Array.new @type = engine.convert_type(@attribute.type) @visibility = @attribute.visibility @multiplicity_range = @attribute.multiplicity_range @clazz = class_builder.name if @type == "String" @initial_value = "\"#{@attribute.initial_value}\"" else @initial_value = "#{@attribute.initial_value}" end #@stereotypes = @attribute.stereotypes #@tagged_values = @attribute.tagged_values @name = @attribute.name.strip @name.gsub!(/[ -]/, "_") column_name = @name.underscore[0, 30] @annotations = Array.new if @type.eql?("java.util.Date") if @attribute.type.include?("DateTime") || @attribute.type.include?("Timestamp") @annotations << "@Temporal(TemporalType.TIMESTAMP)" elsif @attribute.type.include? "Time" @annotations << "@Temporal(TemporalType.TIME)" else @annotations << "@Temporal(TemporalType.DATE)" end @imports << "javax.persistence.Temporal" @imports << "javax.persistence.TemporalType" end if @attribute.is_enum? type_enum = "varchar" if !@attribute.enum_obj.nil? && @attribute.enum_obj.attributes.size > 0 t = engine.convert_type(@attribute.enum_obj.attributes[0].type) if t == "Integer" type_enum = "integer" end end @annotations << "@Column(name=\"#{column_name}\", columnDefinition=\"#{type_enum}\")" @annotations << "@Type(type = \"br.gov.mp.siconv.GenericEnumUserType\", parameters = { @Parameter(name = \"enumClass\", value = \"#{@type}\") })" @imports << "org.hibernate.annotations.Parameter" @imports << "org.hibernate.annotations.Type" else @annotations << "@Column(name=\"#{column_name}\")" end @attribute.tagged_values.each do |t| @comment = t.value if "@andromda.persistence.comment" == t.name @length = t.value if "@andromda.persistence.column.length" == t.name end end |
Instance Attribute Details
#imports ⇒ Object (readonly)
Returns the value of attribute imports.
6 7 8 |
# File 'lib/kody/builder/attribute_builder.rb', line 6 def imports @imports end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/kody/builder/attribute_builder.rb', line 5 def type @type end |
Instance Method Details
#to_liquid ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kody/builder/attribute_builder.rb', line 76 def to_liquid { 'annotations' => @annotations, 'name'=> @name, 'comment' => @comment, 'initial_value' => @initial_value, 'length' => @length, 'type' => @type, 'visibility' => 'public' } end |