Class: Gloo::Verbs::Exists

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

Constant Summary collapse

KEYWORD =
'exists?'.freeze
KEYWORD_SHORT =
'exist'.freeze
VERB_TYPE =
'verb'.freeze
OBJ_TYPE =
'object'.freeze
ANY_TYPE =
'any'.freeze
INSTANCE =
'instance'.freeze
WRONG_NUM_ARGS_ERR =
'Wrong number of arguments! 1 or 2 expected.'.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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gloo/verbs/exists.rb', line 92

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => 'Check to see if a verb or object type has ' \
      'been defined (or loaded). This verb can be used to check ' \
      'if a core library or extension has been loaded.',
    :syntax => [ 'exists? |any,object,verb,instance| {keyword}' ],
    :parameters => [
      "Kind of Keyword — Check for the presence of a keyword of a kind. " \
        "any (default, optional) checks for either an object or a verb; " \
        "object checks for an object matching the keyword or keyword " \
        "shortcut; verb checks for a verb matching the keyword or " \
        "keyword shortcut; instance checks to see if an object " \
        "instance exists at the pathname represented by keyword. " \
        "`exists? any markdown` is identical to `exists? markdown`.",
      '{keyword} — The verb or object keyword or keyword shortcut. ' \
        'Must be specified. For the instance option, the keyword is ' \
        'the pathname to an object instance.'
    ],
    :result => 'If the object or verb has been defined, then true, ' \
      'otherwise false. The result will be in it.',
    :errors => [
      "#{WRONG_NUM_ARGS_ERR} The kind of keyword is optional."
    ],
    :examples => <<~EXAMPLES.strip
      #
      # Example of exists? keyword.
      #
      exists [container] :

      \ton_load [script] :
      \t\texists? object markdown
      \t\tshow it # false

      \t\tload lib md
      \t\texists? object markdown
      \t\tshow it # true

      \t\texists? instance exists.on_load
      \t\tshow it # true
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



40
41
42
# File 'lib/gloo/verbs/exists.rb', line 40

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



47
48
49
# File 'lib/gloo/verbs/exists.rb', line 47

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#runObject

Run the verb.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gloo/verbs/exists.rb', line 22

def run
  if @tokens.token_count == 3
    type = @tokens.second.strip.downcase
    keyword = @tokens.last
  elsif @tokens.token_count == 2
    type = ANY_TYPE
    keyword = @tokens.second
  else
    @engine.err WRONG_NUM_ARGS_ERR
    return
  end
  
  @engine.heap.it.set_to lookup_keyword(keyword, type)
end