lib/gloo/verbs/create.rb in gloo-0.6.1 vs lib/gloo/verbs/create.rb in gloo-0.7.0
- old
+ new
@@ -10,26 +10,25 @@
KEYWORD = 'create'.freeze
KEYWORD_SHORT = '`'.freeze
AS = 'as'.freeze
VAL = ':'.freeze
+ NO_NAME_ERR = 'Object name is missing!'.freeze
#
# Run the verb.
#
def run
name = @tokens.second
type = @tokens.after_token( AS )
value = @tokens.after_token( VAL )
- if Gloo::Expr::LString.string?( value )
- value = Gloo::Expr::LString.strip_quotes( value )
+ unless name
+ $engine.err NO_NAME_ERR
+ return
end
- obj = $engine.factory.create( { name: name, type: type, value: value } )
-
- obj.add_default_children if obj&.add_children_on_create?
- $engine.heap.it.set_to value
+ create name, type, value
end
#
# Get the Verb's keyword.
#
@@ -43,40 +42,26 @@
def self.keyword_shortcut
return KEYWORD_SHORT
end
# ---------------------------------------------------------------------
- # Help
+ # Private functions
# ---------------------------------------------------------------------
+ private
+
#
- # Get help for this verb.
+ # Create an object with given name of given type with
+ # the given initial value.
#
- def self.help
- return <<~TEXT
- CREATE VERB
- NAME: create
- SHORTCUT: `
+ def create( name, type, value )
+ if Gloo::Expr::LString.string?( value )
+ value = Gloo::Expr::LString.strip_quotes( value )
+ end
+ obj = $engine.factory.create( { name: name, type: type, value: value } )
- DESCRIPTION
- Create a new object of given type with given value.
- Both type and value are optional when creating an object.
-
- SYNTAX
- create <new.object.path> as <type> : <value>
-
- PARAMETERS
- new.object.path - The path and name of the new object
- type - The type of the new object
- value - The initial value for the new object
-
- RESULT
- The new object will be created and added to the object heap.
- <it> will be set to the new object's intitial value.
-
- ERRORS
- None
- TEXT
+ obj.add_default_children if obj&.add_children_on_create?
+ $engine.heap.it.set_to value
end
end
end
end