Class: DataMetaJacksonSer::RendCtx

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaJacksonSer/util.rb

Overview

Rendering context with rendering-related properties and settings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRendCtx

Creates a new context.



93
# File 'lib/dataMetaJacksonSer/util.rb', line 93

def initialize; @imps = Set.new; @fmt = JAVA_FMT end

Instance Attribute Details

#baseNameObject

Base name of the type, without a namespace.



75
76
77
# File 'lib/dataMetaJacksonSer/util.rb', line 75

def baseName
  @baseName
end

#fldObject

Field currently on the context.



88
89
90
# File 'lib/dataMetaJacksonSer/util.rb', line 88

def fld
  @fld
end

#fmtObject

Rendering format: either JAVA_FMT or SCALA_FMT



84
85
86
# File 'lib/dataMetaJacksonSer/util.rb', line 84

def fmt
  @fmt
end

#impsObject

Set of imports if any, each as symbol.



66
67
68
# File 'lib/dataMetaJacksonSer/util.rb', line 66

def imps
  @imps
end

#modelObject

DataMeta DOM Model on the context.



57
58
59
# File 'lib/dataMetaJacksonSer/util.rb', line 57

def model
  @model
end

#pckgObject

Java package.



71
72
73
# File 'lib/dataMetaJacksonSer/util.rb', line 71

def pckg
  @pckg
end

#recObject

Record currently worked on.



61
62
63
# File 'lib/dataMetaJacksonSer/util.rb', line 61

def rec
  @rec
end

#refTypeObject

The data type of the entity on the context.



79
80
81
# File 'lib/dataMetaJacksonSer/util.rb', line 79

def refType
  @refType
end

Instance Method Details

#/Object

End of line for the given format - for Java, it’s a semicolon, for Scala - empty string



113
114
115
116
117
118
119
120
121
# File 'lib/dataMetaJacksonSer/util.rb', line 113

def /
  case fmt
    when JAVA_FMT
      ';'
    when SCALA_FMT
      ''
      # all the other options are weeded out in init(...) by calling assertOutFmt
  end
end

#<<(import) ⇒ Object

Add an import to the context, returns self for call chaining.



139
140
141
142
# File 'lib/dataMetaJacksonSer/util.rb', line 139

def <<(import)
    @imps << import.to_sym if import
    self
end

#fTypeObject

Effective field type



159
160
161
# File 'lib/dataMetaJacksonSer/util.rb', line 159

def fType
    isMapping ? @refType.fromT : @fld.dataType
end

#importsTextObject

Formats imports into Java source, sorted.



147
148
149
# File 'lib/dataMetaJacksonSer/util.rb', line 147

def importsText
    @imps.to_a.map{|k| "import #{k};"}.sort.join("\n")
end

#init(model, rec, pckg, baseName, fmt = JAVA_FMT) ⇒ Object

Initialize the context with the model, the record, the package and the basename. Returns self for call chaining.



104
105
106
107
108
# File 'lib/dataMetaJacksonSer/util.rb', line 104

def init(model, rec, pckg, baseName, fmt = JAVA_FMT)
  @model = model; @rec = rec; @pckg = pckg; @baseName = baseName
  @fmt = DataMetaJacksonSer::assertOutFmt(fmt)
  self
end

#isMappingObject

Determines if the refType is a DataMetaDom::Mapping.



154
155
156
# File 'lib/dataMetaJacksonSer/util.rb', line 154

def isMapping
    @refType.kind_of?(DataMetaDom::Mapping) && !@refType.kind_of?(DataMetaDom::BitSet)
end

#rwObject

Readwrap



164
165
166
# File 'lib/dataMetaJacksonSer/util.rb', line 164

def rw
    isMapping ? lambda{|t| "new #{condenseType(@fld.dataType.type, self)}(#{t})"} : lambda{|t| t}
end

#valGetterObject

Getter name for the current field, if the type is Mapping, includes .getKey() too.



171
172
173
# File 'lib/dataMetaJacksonSer/util.rb', line 171

def valGetter
    "#{DataMetaDom.getterName(@fld)}" + ( isMapping ? '.getKey' : '')
end

#|Object

Method call Parentheses for the given format - for Java, it’s (), for Scala - empty string



126
127
128
129
130
131
132
133
134
# File 'lib/dataMetaJacksonSer/util.rb', line 126

def |
  case fmt
    when JAVA_FMT
      '()'
    when SCALA_FMT
      ''
    # all the other options are weeded out in init(...) by calling assertOutFmt
  end
end