Module: DataMetaDom
- Included in:
- Model, PojoLexer, PythonLexer, ScalaLexer
- Defined in:
- lib/dataMetaDom.rb,
lib/dataMetaDom/ora.rb,
lib/dataMetaDom/ref.rb,
lib/dataMetaDom/ver.rb,
lib/dataMetaDom/docs.rb,
lib/dataMetaDom/enum.rb,
lib/dataMetaDom/help.rb,
lib/dataMetaDom/pojo.rb,
lib/dataMetaDom/util.rb,
lib/dataMetaDom/field.rb,
lib/dataMetaDom/model.rb,
lib/dataMetaDom/mySql.rb,
lib/dataMetaDom/scala.rb,
lib/dataMetaDom/python.rb,
lib/dataMetaDom/record.rb,
lib/dataMetaDom/recAttr.rb,
lib/dataMetaDom/sources.rb,
lib/dataMetaDom/dataType.rb,
lib/dataMetaDom/converter.rb,
lib/dataMetaDom/sourceFile.rb
Overview
DataMeta DOM infrastructure root.
For command line details either check the new method’s source or the README.rdoc file, the usage section.
Defined Under Namespace
Modules: MySqlLexer, OraLexer, PojoLexer, PythonLexer, ScalaLexer Classes: BitSet, Converter, DataType, DimInfo, Doc, Documentable, Enum, Field, Mapping, Mappings, MigrCtx, Model, RecAttr, RecAttrList, RecAttrSet, RecIdentity, RecIndex, RecUnique, Record, Reference, RegExEntry, RegExRoster, SemVer, SourceFile, Sources, Ver, VerDoccable
Constant Summary collapse
- VERSION =
Current version
'1.0.7'
- JAVA_DOC_TARGET =
doc target for javadocs
:java
- PLAIN_DOC_TARGET =
doc target for plaintext
:plain
- DOC_TARGETS =
All documentation targets
Set.new [PLAIN_DOC_TARGET, JAVA_DOC_TARGET]
- L =
Logger set to WARN, daily rollover and max size 10M Feel free to change any of it.
Logger.new('dataMetaDom.log', 'daily', 10*1024*1024)
- NAMESPACE =
Keyword: namespace
:namespace
- INCLUDE =
Keyword: include
:include
- CHAR =
Keyword, data type: string with fixed length
:char
- STRING =
Keyword, data type: string with variable length
:string
- INT =
Keyword, data type: integer
:int
- FLOAT =
Keyword, data type: float (real numbers)
:float
- BOOL =
Keyword, data type: boolean
:bool
- BITSET =
Keyword, data type: bitset
:bitset
- URL =
Keyword, data type: URL
:url
- MAPPING =
Keyword, data type: map
:mapping
- DATETIME =
Keyword, data type: datetime
:datetime
- NUMERIC =
Keyword, data type: numeric
:numeric
- IDENTITY =
Keyword, identity
:identity
- UNIQUE =
Keyword, unique
:unique
- MATCHES =
Keyword, matches
:matches
- INDEX =
Keyword, index
:index
- NO_NAMESPACE =
Key to a no-namespace
''.to_sym
- WIKI =
Wiki for DataMeta DOM
'https://github.com/eBayDataMeta/DataMeta'
- WIKI_REF_HTML =
HTML tag referencing the WIKI
"<a href='#{WIKI}'>DataMeta</a>"
- RAW =
Keyword, data type, the RAW type refers to raw data, like a byte array
:raw
- DOC =
Keyword
doc
, documentation. :doc
- VER_KW =
Keyword
ver
, version info. :ver
- ENUM =
Keyword, data type, enum
:enum
- END_KW =
Keyword, end
:end
- RECORD =
Keyword, record
:record
- PACK_SEPARATOR =
Package separator in a namespace.
'.'
- DATAMETA_LIB =
Environment variable for DataMeta DOM library path.
'DATAMETA_LIB'
- SOURCE_INDENT =
for source code generation, 2 spaces
' ' * 2
- REQUIRED_PFX =
Prefix for a required field
'+'.to_sym
- OPTIONAL_PFX =
Prefix for an optional field
'-'.to_sym
- SCALE_TYPES =
DataMeta DOM standard types that have a dimension with a scale
Set.new [NUMERIC]
- DIMMED_TYPES =
Data Types that must be dimensioned, with a length or with a length and a scale, as it includes all the SCALE_TYPES too..
Set.new ([FLOAT, INT, CHAR, RAW] << SCALE_TYPES.to_a).flatten
- OPT_DIMMABLE =
Optionally dimmable types - may have a dim or may have not
Set.new ([STRING]).flatten
- STANDARD_TYPES =
standard types is a superset of dimmensionable types, adding BOOL and DATETIME
Set.new(([BOOL, DATETIME, URL] << DIMMED_TYPES.to_a << OPT_DIMMABLE.to_a << SCALE_TYPES.to_a).flatten)
- REC_ATTR_KEYWORDS =
Record attribute keywords:
-
identity
-
unique
-
index
-
Set.new [IDENTITY, UNIQUE, INDEX]
- ID_START =
Valid first symbol of a DataMeta DOM idenifier such as entity or enum name, field name, enum item.
'[A-Za-z_]'
- TYPE_START =
Valid first symbol for a DataMeta DOM Type
'[A-Z]'
- SAME_FULL_SFX =
Suffix for the java source files for the implementors of the DataMetaSame interface by all the fields on the class.
'_DmSameFull'
- SAME_ID_SFX =
Suffix for the java source files for the implementors of the DataMetaSame interface by identity field(s) on the class.
'_DmSameId'
- FULL_COMPARE =
DataMetaSame
generation style: Full Compare, compare by all the fields defined in the class :full
- ID_ONLY_COMPARE =
DataMetaSame
generation style: Compare by the identity fields only as defined on DataMetaDom::Record :id
- INDENT =
One indent step for java classes, spaces.
' ' * 4
- CANNED_RX =
keep in sync with generated classes such as the Java class ‘CannedRegexUtil` in DataMeta DOM Core/Java etc.
Set.new [:email, :phone, :uuid, :UUID]
- MODEL_LEVEL_TOKENS =
DataMeta DOM source tokens on the Model level:
-
Record
-
Enum
-
BitSet
-
Map
-
[Record, Enum, BitSet, Mappings]
- RECORD_LEVEL_TOKENS =
An array of record level parse token classes, namely RecIdentity, RecIndex, RecUnique
[RecIdentity, RecIndex, RecUnique]
- INT1 =
Reusable type - Integer of the length 1, aka Java’s
byte
. DataType.new(INT, 1)
- INT2 =
Reusable type - Integer of the length 2, aka Java’s
short
. DataType.new(INT, 2)
- INT4 =
Reusable type - Integer of the length 4, aka Java’s
int
. DataType.new(INT, 4)
- INT8 =
Reusable type - Integer of the length 8, aka Java’s
long
. DataType.new(INT, 8)
- FLOAT4 =
Reusable type - Float (Real number) of the length 4, aka Java’s
float
. DataType.new(FLOAT, 4)
- FLOAT8 =
Reusable type - Float (Real number) of the length 8, aka Java’s
double
. DataType.new(FLOAT, 8)
- DTTM_TYPE =
Reusable type - DATETIME, in Java projected into
java.time.ZonedDateTime
. DataType.new(DATETIME)
- URL_TYPE =
Reusable type - URL, in Java projected into
java.net.URL
. DataType.new(URL)
- INTEGRAL_CONV =
Converter for the integral types, meaning no fraction.
Converter.new(lambda { |i| i ? i.to_s : nil }, lambda { |s| s ? s.to_i : nil })
- FRACT_CONV =
Numbers with fraction, such as real numbers, aka floating point.
Converter.new(lambda { |f| f ? f.to_s : nil }, lambda { |s| s ? s.to_f : nil })
- BOOL_CONV =
Converter for boolean.
Converter.new(lambda { |b| b ? b.to_s : nil }, lambda { |s| s && !s.empty? ? ("TY1ty1".index(s[0]) ? true : false) : nil })
- DTTM_CONV =
Converter for datetime.
Converter.new(lambda { |d| d ? "DateTime.parse('#{d}')" : nil }, lambda { |s| s ? DateTime.parse(s) : nil })
- TEXT_CONV =
Conterter for textual types, such as string or char.
Converter.new(lambda { |src| src.inspect }, lambda { |src| eval(src) })
- CONVS =
All Converters hash keyed by the type, referencing an instance of the Converter class.
{INT => INTEGRAL_CONV, STRING => TEXT_CONV, CHAR => TEXT_CONV, FLOAT => FRACT_CONV, NUMERIC => FRACT_CONV, BOOL => BOOL_CONV, DATETIME => DTTM_CONV, URL => TEXT_CONV}
Class Method Summary collapse
-
.combineNsBase(namespace, base) ⇒ String
Combines the namespace with the base name: if the namespace is empty or
nil
, returns the base name as a symbol, otherwise returns namespace.base. -
.condenseType(fullType, ref_namespace) ⇒ Object
With the given full type including the namespace if any and the given namespace (java package, python package etc), figures out whether the full type has to be reference in full, if it belongs to a different namespace, or just by the base name if it belongs to the same package.
-
.fullTypeName(namespace, name) ⇒ Object
if name is a standard type, return it.
-
.getParenDimInfo(dimSpec) ⇒ Object
# Parses parenthesized dimension info such as (18, 2) or just (18).
-
.getterName(f) ⇒ Object
Builds and returns the Java-style getter name for the given field.
-
.help(file, purpose, params, errorText = nil) ⇒ Object
Helper method for runnables.
-
.helpAndVerFirstArg ⇒ Object
Adds options to help and version from the first argument And shortcuts to showing the help screen if the ARGV is empty.
-
.helpMySqlDdl(file, errorText = nil) ⇒ Object
Shortcut to help for the MySQL DDL Generator.
-
.helpPojoGen(file, errorText = nil) ⇒ Object
Shortcut to help for the Pojo Generator.
-
.helpScalaGen(file, errorText = nil) ⇒ Object
Shortcut to help for the Pojo Generator.
-
.nsAdjustment(namespace, options, src) ⇒ Object
adjust the namespace if required.
-
.setterName(f) ⇒ Object
Builds and returns the Java-setter setter name for the given field.
-
.splitNameSpace(source) ⇒ Array
Returns an array of the namespace and the base, first element nil if no namespace both elements nil if not a proper namespace.
-
.uniPath(source) ⇒ Object
Quick and dirty turning a Windows path into a path of the platform on which this script is running.
-
.validNs?(namespace, base) ⇒ Boolean
Given the namespace and the base, returns true if the namespace is a valid one.
Instance Method Summary collapse
-
#helpOracleDdl(file, errorText = nil) ⇒ Object
Shortcut to help for the Oracle DDL Generator.
-
#migrClass(base, ver1, ver2) ⇒ Object
Migrator implementor name.
-
#qualName(namespace, name) ⇒ Object
Returns qualified name for the given namespace: strips the namespace if the namespace is the same, or keep it.
Class Method Details
.combineNsBase(namespace, base) ⇒ String
Combines the namespace with the base name: if the namespace is empty or nil
, returns the base name as a symbol, otherwise returns namespace.base
62 63 64 |
# File 'lib/dataMetaDom.rb', line 62 def combineNsBase(namespace, base) namespace && !namespace.empty? ? "#{namespace}.#{base}".to_sym : base.to_sym end |
.condenseType(fullType, ref_namespace) ⇒ Object
With the given full type including the namespace if any and the given namespace (java package, python package etc), figures out whether the full type has to be reference in full, if it belongs to a different namespace, or just by the base name if it belongs to the same package.
-
Parameters
-
fullType
- full data type including the namespace if any -
namespace
- reference namespace.
-
For example, passed:
"com.acme.proj.Klass", "com.acme.lib"
will return
"com.acme.proj.Klass"
but when passed:
"com.acme.proj.Klass", "com.acme.proj"
will return
"Klass"
This is to avoid excessive verbosity when referencing entities in the same package.
256 257 258 259 260 |
# File 'lib/dataMetaDom/util.rb', line 256 def condenseType(fullType, ref_namespace) ns, base = DataMetaDom.splitNameSpace(fullType) # noinspection RubyNestedTernaryOperatorsInspection DataMetaDom.validNs?(ns, base) ? ( ns == ref_namespace ? base : fullType) : fullType end |
.fullTypeName(namespace, name) ⇒ Object
if name is a standard type, return it. if name is a fully qualified namespaced name, return it otherwise, combine the namespace provided with the base to return the full name
81 82 83 84 85 |
# File 'lib/dataMetaDom.rb', line 81 def fullTypeName(namespace, name) #noinspection RubyUnusedLocalVariable ns, _ = splitNameSpace(name.to_s) # if it is already a full namespaced name or a standard type, return original validNs?(ns, name) || STANDARD_TYPES.member?(name) ? name.to_sym : "#{combineNsBase(namespace, name)}".to_sym end |
.getParenDimInfo(dimSpec) ⇒ Object
# Parses parenthesized dimension info such as (18, 2) or just (18)
Returns DimInfo::NIL if the dimSpec is nil
or the DimInfo instance as specified
121 122 123 124 125 126 |
# File 'lib/dataMetaDom.rb', line 121 def getParenDimInfo(dimSpec) return DimInfo::NIL unless dimSpec result = dimSpec =~ /^\s*\(\s*(\d+)\s*(?:,\s*(\d+))?\s*\)\s*$/ raise "Invalid dimension specification: '#{dimSpec}'" unless result DimInfo.new($1.to_i, $2.to_i) end |
.getterName(f) ⇒ Object
Builds and returns the Java-style getter name for the given field. This style is used in other platforms such as Python, for consistency.
269 |
# File 'lib/dataMetaDom/util.rb', line 269 def getterName(f); "get#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end |
.help(file, purpose, params, errorText = nil) ⇒ Object
Helper method for runnables.
Prints help and exits placing the purpose of the runnable and the parameters description in proper spots.
Exits with code 0 if errorText is nil
, exits with code 1 otherwise. Prints errorText with proper dressing to the STDERR
.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dataMetaDom/help.rb', line 13 def help(file, purpose, params, errorText = nil) puts <<HELP DataMeta DOM version #{DataMetaDom::VERSION} #{purpose}. Usage: #{File.basename(file)} #{params} HELP $stdout.flush # otherwise it may mix up with the $stderr output below $stderr.puts "\nERROR: #{errorText}" if errorText exit errorText ? 0 : 1 end |
.helpAndVerFirstArg ⇒ Object
Adds options to help and version from the first argument And shortcuts to showing the help screen if the ARGV is empty. The options for help are either --help
or </tt>-h</tt>. The option for show version and exit is either --version
or -v
.
134 135 136 137 |
# File 'lib/dataMetaDom.rb', line 134 def helpAndVerFirstArg raise Trollop::HelpNeeded if ARGV.empty? || ARGV[0] == '--help' || ARGV[0] == '-h' # show help screen raise Trollop::VersionNeeded if ARGV[0] == '--version' || ARGV[0].downcase == '-v' # show version screen end |
.helpMySqlDdl(file, errorText = nil) ⇒ Object
Shortcut to help for the MySQL DDL Generator.
37 38 39 |
# File 'lib/dataMetaDom/help.rb', line 37 def helpMySqlDdl(file, errorText=nil) help(file, 'MySQL DDL generator', '<DataMeta DOM source> <target directory>', errorText) end |
.helpPojoGen(file, errorText = nil) ⇒ Object
Shortcut to help for the Pojo Generator.
27 28 29 |
# File 'lib/dataMetaDom/help.rb', line 27 def helpPojoGen(file, errorText=nil) help(file, 'POJO generator', '<DataMeta DOM source> <target directory>', errorText) end |
.helpScalaGen(file, errorText = nil) ⇒ Object
Shortcut to help for the Pojo Generator.
32 33 34 |
# File 'lib/dataMetaDom/help.rb', line 32 def helpScalaGen(file, errorText=nil) help(file, 'Scala generator', '<DataMeta DOM source> <target directory>', errorText) end |
.nsAdjustment(namespace, options, src) ⇒ Object
adjust the namespace if required
51 52 53 |
# File 'lib/dataMetaDom.rb', line 51 def nsAdjustment(namespace, , src) src && [:autoVerNs] ? "#{namespace}.v#{src.ver.full.toVarName}" : namespace end |
.setterName(f) ⇒ Object
Builds and returns the Java-setter setter name for the given field. This style is used in other platforms such as Python, for consistency.
275 |
# File 'lib/dataMetaDom/util.rb', line 275 def setterName(f); "set#{DataMetaXtra::Str.capFirst(f.name.to_s)}" end |
.splitNameSpace(source) ⇒ Array
Returns an array of the namespace and the base, first element nil if no namespace both elements nil if not a proper namespace.
44 45 46 47 48 |
# File 'lib/dataMetaDom.rb', line 44 def splitNameSpace(source) #noinspection RubyNestedTernaryOperatorsInspection source =~ /(\w[\w\.]*)\.(#{TYPE_START}\w*)/ ? [($1.empty? ? nil : $1), $2] : (source =~ /(#{TYPE_START}\w*)/ ? [nil, source] : [nil, nil]) end |
.uniPath(source) ⇒ Object
Quick and dirty turning a Windows path into a path of the platform on which this script is running. Assumes that backslash is never used as a part of a directory name, pretty safe assumption.
34 35 36 |
# File 'lib/dataMetaDom.rb', line 34 def uniPath(source) source.gsub(/\\/, File::SEPARATOR) end |
.validNs?(namespace, base) ⇒ Boolean
Given the namespace and the base, returns true if the namespace is a valid one.
72 73 74 |
# File 'lib/dataMetaDom.rb', line 72 def validNs?(namespace, base) namespace && !namespace.empty? && namespace.to_sym != base end |
Instance Method Details
#helpOracleDdl(file, errorText = nil) ⇒ Object
Shortcut to help for the Oracle DDL Generator.
42 43 44 |
# File 'lib/dataMetaDom/help.rb', line 42 def helpOracleDdl(file, errorText=nil) help(file, 'Oracle DDL generator', '<DataMeta DOM source> <target directory>', errorText) end |
#migrClass(base, ver1, ver2) ⇒ Object
Migrator implementor name
263 |
# File 'lib/dataMetaDom/util.rb', line 263 def migrClass(base, ver1, ver2); "Migrate_#{base}_v#{ver1.toVarName}_to_v#{ver2.toVarName}" end |
#qualName(namespace, name) ⇒ Object
Returns qualified name for the given namespace: strips the namespace if the namespace is the same, or keep it
88 89 90 91 |
# File 'lib/dataMetaDom.rb', line 88 def qualName(namespace, name) ns, b = splitNameSpace(name.to_s) !STANDARD_TYPES.member?(name.to_sym) && (!validNs?(ns, b) || ns == namespace) ? b : name end |