Class: DataMetaJacksonSer::RendCtx
- Inherits:
-
Object
- Object
- DataMetaJacksonSer::RendCtx
- Defined in:
- lib/dataMetaJacksonSer/util.rb
Overview
Rendering context with rendering-related properties and settings.
Instance Attribute Summary collapse
-
#baseName ⇒ Object
Base name of the type, without a namespace.
-
#fld ⇒ Object
Field currently on the context.
-
#fmt ⇒ Object
Rendering format: either JAVA_FMT or SCALA_FMT.
-
#imps ⇒ Object
Set of imports if any, each as symbol.
-
#model ⇒ Object
DataMeta DOM Model on the context.
-
#pckg ⇒ Object
Java package.
-
#rec ⇒ Object
Record currently worked on.
-
#refType ⇒ Object
The data type of the entity on the context.
Instance Method Summary collapse
-
#/ ⇒ Object
End of line for the given format - for Java, it’s a semicolon, for Scala - empty string.
-
#<<(import) ⇒ Object
Add an import to the context, returns self for call chaining.
-
#fType ⇒ Object
Effective field type.
-
#importsText ⇒ Object
Formats imports into Java source, sorted.
-
#init(model, rec, pckg, baseName, fmt = JAVA_FMT) ⇒ Object
Initialize the context with the model, the record, the package and the basename.
-
#initialize ⇒ RendCtx
constructor
Creates a new context.
-
#isMapping ⇒ Object
Determines if the refType is a DataMetaDom::Mapping.
-
#rw ⇒ Object
Readwrap.
-
#valGetter ⇒ Object
Getter name for the current field, if the type is Mapping, includes
.getKey()
too. -
#| ⇒ Object
Method call Parentheses for the given format - for Java, it’s (), for Scala - empty string.
Constructor Details
Instance Attribute Details
#baseName ⇒ Object
Base name of the type, without a namespace.
75 76 77 |
# File 'lib/dataMetaJacksonSer/util.rb', line 75 def baseName @baseName end |
#fld ⇒ Object
Field currently on the context.
88 89 90 |
# File 'lib/dataMetaJacksonSer/util.rb', line 88 def fld @fld end |
#fmt ⇒ Object
Rendering format: either JAVA_FMT or SCALA_FMT
84 85 86 |
# File 'lib/dataMetaJacksonSer/util.rb', line 84 def fmt @fmt end |
#imps ⇒ Object
Set of imports if any, each as symbol.
66 67 68 |
# File 'lib/dataMetaJacksonSer/util.rb', line 66 def imps @imps end |
#model ⇒ Object
DataMeta DOM Model on the context.
57 58 59 |
# File 'lib/dataMetaJacksonSer/util.rb', line 57 def model @model end |
#pckg ⇒ Object
Java package.
71 72 73 |
# File 'lib/dataMetaJacksonSer/util.rb', line 71 def pckg @pckg end |
#rec ⇒ Object
Record currently worked on.
61 62 63 |
# File 'lib/dataMetaJacksonSer/util.rb', line 61 def rec @rec end |
#refType ⇒ Object
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 |
#fType ⇒ Object
Effective field type
159 160 161 |
# File 'lib/dataMetaJacksonSer/util.rb', line 159 def fType isMapping ? @refType.fromT : @fld.dataType end |
#importsText ⇒ Object
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 |
#isMapping ⇒ Object
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 |
#rw ⇒ Object
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 |
#valGetter ⇒ Object
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 |