Adding type and source default functions to give better representation of the origin of the object.
This commit is contained in:
parent
f4497f646c
commit
32853941a7
1 changed files with 6 additions and 3 deletions
9
oop.sh
9
oop.sh
|
@ -69,14 +69,17 @@ _createObject() {
|
||||||
|
|
||||||
# Declare dummy constructor.
|
# Declare dummy constructor.
|
||||||
eval "$varName.constructor() { :; }"
|
eval "$varName.constructor() { :; }"
|
||||||
|
# Declare base properties.
|
||||||
|
eval "$varName.type() { echo $type; }"
|
||||||
|
eval "$varName.source() { echo $associatedFile; }"
|
||||||
# Create property array.
|
# Create property array.
|
||||||
eval "declare -Ag _${varName}_properties"
|
eval "declare -Ag _${varName}_properties"
|
||||||
|
# alias the "varName" variable to itself, so that it can be used and transmitted in other variables (e.g: $varName.name would alias to varName.name)
|
||||||
|
eval "$varName='$varName'"
|
||||||
# Imports the file and replace all "<Type>." with the variable name.
|
# Imports the file and replace all "<Type>." with the variable name.
|
||||||
. <(sed s/this\\./$varName./g <(sed s/$type\\./$varName./g $associatedFile))
|
. <(sed s/this\\./$varName./g <(sed s/$type\\./$varName./g $associatedFile))
|
||||||
# Call the constructor
|
# Call the constructor
|
||||||
eval "$varName.constructor $constructorArguments"
|
$varName.constructor $constructorArguments
|
||||||
# alias the "varName" variable to itself, so that it can be used and transmitted in other variables (e.g: $varName.name would alias to varName.name)
|
|
||||||
eval "$varName='$varName'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Object creation.
|
# Object creation.
|
||||||
|
|
Loading…
Reference in a new issue