Class: Liquigen::Scaffold::Schema

Inherits:
Base
  • Object
show all
Defined in:
lib/liquigen/scaffold/schema.rb

Instance Attribute Summary

Attributes inherited from Base

#name, #props

Instance Method Summary collapse

Methods inherited from Base

#directory, #file_append, #file_name, #initialize, #process, #write_lines

Constructor Details

This class inherits a constructor from Liquigen::Scaffold::Base

Instance Method Details

#class_linesObject



22
23
24
25
26
27
28
29
# File 'lib/liquigen/scaffold/schema.rb', line 22

def class_lines
  [
    "@Getter",
    '@Setter',
    "@PresentationSchema(name = \"#{name.singularize}\")",
    "public class #{name.singularize.camelize} {"
  ]
end

#current_packageObject



5
6
7
# File 'lib/liquigen/scaffold/schema.rb', line 5

def current_package
  Liquigen.schema_package_name
end

#import_linesObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/liquigen/scaffold/schema.rb', line 9

def import_lines
  [
    "package #{current_package};",
    '',
    'import com.dyg.backend.config.Constants;',
    'import com.dyg.schemas.*;',
    'import lombok.Getter;',
    'import lombok.Setter;',
    '',
    'import java.util.Date;'
  ]
end

#methods_linesObject



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
75
76
77
# File 'lib/liquigen/scaffold/schema.rb', line 31

def methods_lines
  lines = []
  skip_ones = %w[id created_at updated_at]
  lines += [
    '@PresentationField(primary = true, i18nKey = Constants.I18nCommon.Property.ID, type = FieldType.Number)',
    '@PresentationColumn(type = ColumnType.LinkShow, width = "50px")',
    '@PresentationDetailField',
    'private Long id;',
    ''
  ]
  props.each do |property|
    key, value = property.to_s.split(':')
    next if skip_ones.include?(key.underscore)
    next if key.casecmp('available').zero?

    type = Liquigen::TypeMap.new(value).java_type
    stype = Liquigen::TypeMap.new(value).statement_type

    if (stype && !stype.size.zero?)
      lines += ["@PresentationField(type = FieldType.#{stype})"]
    else
      lines += ["@PresentationField//(i18nKey = Constants.I18nCommon.Property.#{key.upcase})"]
    end

    lines += [
      '@PresentationColumn',
      '@PresentationFormField(rules = { @PresentationRule(required = true) })',
      '@PresentationDetailField',
      '//@PresentationSearchField',
      "private #{type} #{key.camelize(:lower)};",
      ''
    ]
  end

  lines += [
    '@PresentationField(type = FieldType.Datetime, i18nKey = Constants.I18nCommon.Property.CREATED_AT)',
    '@PresentationColumn(width = "140px")',
    '@PresentationDetailField',
    'private Date createdAt;',
    '',
    '@PresentationField(type = FieldType.Datetime, i18nKey = Constants.I18nCommon.Property.UPDATED_AT)',
    '@PresentationColumn(width = "140px")',
    '@PresentationDetailField',
    'private Date updatedAt;'
  ]
  lines
end