Class: Gloo::Verbs::Create

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/create.rb

Constant Summary collapse

KEYWORD =
'create'.freeze
KEYWORD_SHORT =
'`'.freeze
AS =
'as'.freeze
VAL =
':'.freeze
NO_NAME_ERR =
'Object name is missing!'.freeze

Constants inherited from Core::Baseo

Core::Baseo::NOT_IMPLEMENTED_ERR

Instance Attribute Summary

Attributes inherited from Core::Verb

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.doc_dataObject

Get the verb's documentation data.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gloo/verbs/create.rb', line 79

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :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. Optional; if not provided the object will be untyped.',
      "{value} — The initial value for the new object. Optional; if not provided the object will have the default value for the type."
    ],
    :result => "The new object will be created and added to the " \
      "object heap. It will be set to the new object's initial value.",
    :errors => [
      "#{NO_NAME_ERR} — The name of the object was not specified and the object cannot be created."
    ],
    :examples => <<~EXAMPLES.strip
      # Basic examples of creating an object from the gloo shell:
      > create x as integer : 1
      > create s : "abc"
      > create t

      # Example of creating an object with an alias:
      a [can] :
        ln [alias] : x

        on_load [script] :
          create a.ln* as string
          put 'test' into x
          show a.ln
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



35
36
37
# File 'lib/gloo/verbs/create.rb', line 35

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



42
43
44
# File 'lib/gloo/verbs/create.rb', line 42

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#runObject

Run the verb.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gloo/verbs/create.rb', line 20

def run
  name = @tokens.second
  type = @tokens.after_token( AS )
  value = @tokens.after_token( VAL )

  unless name
    @engine.err NO_NAME_ERR
    return
  end
  create name, type, value
end