Module: Morpheus::Cli::RestCommand::ClassMethods

Defined in:
lib/morpheus/cli/mixins/rest_command.rb

Instance Method Summary collapse

Instance Method Details

#clear_registered_interfacesObject

clear the list of registered interfaces, perhaps useful in a command subclass



320
321
322
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 320

def clear_registered_interfaces()
  @registered_interfaces = []
end

#default_rest_argObject



79
80
81
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 79

def default_rest_arg
  rest_key.gsub("_", " ") # "[" + rest_key.gsub("_", " ") + "]"
end

#default_rest_has_nameObject



95
96
97
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 95

def default_rest_has_name
  true
end

#default_rest_has_typeObject



178
179
180
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 178

def default_rest_has_type
  false
end

#default_rest_interface_nameObject



141
142
143
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 141

def default_rest_interface_name
  rest_name
end

#default_rest_keyObject



64
65
66
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 64

def default_rest_key
  rest_name.to_s.chomp("s")
end

#default_rest_labelObject



110
111
112
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 110

def default_rest_label
  rest_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
end

#default_rest_label_pluralObject



125
126
127
128
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 125

def default_rest_label_plural
  #rest_name.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
  rest_label.to_s.pluralize
end

#default_rest_nameObject



49
50
51
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 49

def default_rest_name
  self.command_name.to_s.gsub("-", "_")
end

#default_rest_type_argObject



226
227
228
229
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 226

def default_rest_type_arg
  # rest_type_key.gsub("_", " ") # "[" + rest_key.gsub("_", " ") + "]"
  "type" # [type]
end

#default_rest_type_interface_nameObject



273
274
275
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 273

def default_rest_type_interface_name
  rest_type_name
end

#default_rest_type_keyObject



212
213
214
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 212

def default_rest_type_key
  rest_type_name.chomp("s")
end

#default_rest_type_labelObject



242
243
244
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 242

def default_rest_type_label
  rest_type_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
end

#default_rest_type_label_pluralObject



257
258
259
260
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 257

def default_rest_type_label_plural
  #rest_type_name.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
  rest_type_label.to_s.pluralize
end

#default_rest_type_nameObject



195
196
197
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 195

def default_rest_type_name
  rest_key + "_types"
end

#register_interfaces(*interfaces) ⇒ Object Also known as: register_interface

set or append to the list of interface names to register for this command The registered interfaces will be pre-loaded into instance variables eg. [:neat_things, :neat_thing_types] will instantiate @neat_things_interface and @neat_thing_types_interface



286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 286

def register_interfaces(*interfaces)
  @registered_interfaces ||= []
  interfaces.flatten.each do |it|
    @registered_interfaces << it.to_s
  end
  # put the default rest_interface first
  if rest_interface_name && !@registered_interfaces.include?(rest_interface_name)
    @registered_interfaces.unshift(rest_interface_name)
  end
  # and also the rest_type_interface
  if rest_has_type && !@registered_interfaces.include?(rest_type_interface_name)
    @registered_interfaces.unshift(rest_type_interface_name)
  end
end

#registered_interfacesObject

get list of interface names that are registered for this command automatically includes the interface for the rest_name and rest_type_name if has_type



305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 305

def registered_interfaces
  @registered_interfaces ||= []
  # put the default rest_interface first
  if @registered_interfaces.empty?
    if rest_interface_name
      @registered_interfaces.unshift(rest_interface_name)
    end
    if rest_has_type
      @registered_interfaces.unshift(rest_type_interface_name)
    end
  end
  @registered_interfaces
end

#rest_argObject

rest_arg is a label for the arg in the command usage eg. “thing” gets displayed as [thing]



75
76
77
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 75

def rest_arg
  defined?(@rest_arg) ? @rest_arg : default_rest_arg
end

#rest_arg=(v) ⇒ Object Also known as: set_rest_arg



83
84
85
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 83

def rest_arg=(v)
  @rest_arg = v.to_s
end

#rest_has_nameObject

rest_has_name indicates a resource has a name and can be retrieved by name or id true by default, set to false for lookups by only id



91
92
93
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 91

def rest_has_name
  defined?(@rest_has_name) ? @rest_has_name :  default_rest_has_name
end

#rest_has_name=(v) ⇒ Object Also known as: set_rest_has_name



99
100
101
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 99

def rest_has_name=(v)
  @rest_has_name = !!v
end

#rest_has_typeObject

rest_has_type indicates a resource has a type. default is false



174
175
176
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 174

def rest_has_type
  defined?(@rest_has_type) && @rest_has_type
end

#rest_has_type=(v) ⇒ Object Also known as: set_rest_has_type



182
183
184
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 182

def rest_has_type=(v)
  @rest_has_type = !!v
end

#rest_interface_nameObject

rest_interface_name is the interface name for the resource. eg. “neat_things”



137
138
139
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 137

def rest_interface_name
  defined?(@rest_interface_name) ? @rest_interface_name : default_rest_interface_name
end

#rest_interface_name=(v) ⇒ Object Also known as: set_rest_interface_name



145
146
147
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 145

def rest_interface_name=(v)
  @rest_interface_name = v.to_s
end

#rest_keyObject

rest_key is the singular name of the resource eg. “neat_thing”



60
61
62
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 60

def rest_key
  defined?(@rest_key) ? @rest_key : default_rest_key
end

#rest_key=(v) ⇒ Object Also known as: set_rest_key



68
69
70
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 68

def rest_key=(v)
  @rest_key = v.to_s
end

#rest_labelObject

rest_label is the capitalized resource label eg. “Neat Thing”



106
107
108
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 106

def rest_label
  defined?(@rest_label) ? @rest_label : default_rest_label
end

#rest_label=(v) ⇒ Object Also known as: set_rest_label



114
115
116
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 114

def rest_label=(v)
  @rest_label = v.to_s
end

#rest_label_pluralObject

the plural version of the label eg. “Neat Things”



121
122
123
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 121

def rest_label_plural
  defined?(@rest_label_plural) ? @rest_label_plural : default_rest_label_plural
end

#rest_label_plural=(v) ⇒ Object Also known as: set_rest_label_plural



130
131
132
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 130

def rest_label_plural=(v)
  @rest_label_plural = v.to_s
end

#rest_nameObject

rest_name is the plural name of the resource eg. NeatThings would be “neat_things” It is used to derive all other default rest settings key, label, etc.

The default name the command name with underscores ‘_` instead of dashes `-`.



45
46
47
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 45

def rest_name
  defined?(@rest_name) ? @rest_name : default_rest_name
end

#rest_name=(v) ⇒ Object Also known as: set_rest_name



53
54
55
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 53

def rest_name=(v)
  @rest_name = v.to_s
end

#rest_option_context_mapObject

rest_option_context_map specifies context mapping during option prompt. default is domain => ”



163
164
165
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 163

def rest_option_context_map
  defined?(@option_context_map) ? @option_context_map : {'domain' => ''}
end

#rest_option_context_map=(v) ⇒ Object Also known as: set_rest_option_context_map



167
168
169
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 167

def rest_option_context_map=(v)
  @option_context_map = v
end

#rest_perms_configObject

rest_perms_config enables and configures permissions prompt



152
153
154
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 152

def rest_perms_config
  defined?(@rest_perms_config) ? @rest_perms_config : {}
end

#rest_perms_config=(v) ⇒ Object Also known as: set_rest_perms_config



156
157
158
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 156

def rest_perms_config=(v)
  @rest_perms_config = v
end

#rest_type_argObject



222
223
224
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 222

def rest_type_arg
  defined?(@rest_type_arg) ? @rest_type_arg : default_rest_type_arg
end

#rest_type_arg=(v) ⇒ Object Also known as: set_rest_type_arg



231
232
233
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 231

def rest_type_arg=(v)
  @rest_type_arg = v.to_s
end

#rest_type_interface_nameObject

the name of the default interface, matches the rest name eg. “neat_things”



269
270
271
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 269

def rest_type_interface_name
  defined?(@rest_type_interface_name) ? @rest_type_interface_name : default_rest_type_interface_name
end

#rest_type_interface_name=(v) ⇒ Object Also known as: set_rest_type_interface_name



277
278
279
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 277

def rest_type_interface_name=(v)
  @rest_type_interface_name = v.to_s
end

#rest_type_keyObject

rest_type_key is the singular name of the resource eg. “neat_thing”



208
209
210
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 208

def rest_type_key
  defined?(@rest_type_key) ? @rest_type_key : default_rest_type_key
end

#rest_type_key=(v) ⇒ Object Also known as: set_rest_type_key



216
217
218
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 216

def rest_type_key=(v)
  @rest_type_key = v.to_s
end

#rest_type_labelObject

rest_type_label is the capitalized resource label eg. “Neat Thing”



238
239
240
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 238

def rest_type_label
  defined?(@rest_type_label) ? @rest_type_label : default_rest_type_label
end

#rest_type_label=(v) ⇒ Object Also known as: set_rest_type_label



246
247
248
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 246

def rest_type_label=(v)
  @rest_type_label = v.to_s
end

#rest_type_label_pluralObject

the plural version of the label eg. “Neat Things”



253
254
255
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 253

def rest_type_label_plural
  defined?(@rest_type_label_plural) ? @rest_type_label_plural : default_rest_type_label_plural
end

#rest_type_label_plural=(v) ⇒ Object Also known as: set_rest_type_label_plural



262
263
264
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 262

def rest_type_label_plural=(v)
  @rest_type_label_plural = v.to_s
end

#rest_type_nameObject

rest_type_name is the rest_name for the type, only applicable if rest_has_type



191
192
193
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 191

def rest_type_name
  defined?(@rest_type_name) ? @rest_type_name : default_rest_type_name
end

#rest_type_name=(v) ⇒ Object Also known as: set_rest_type_name, set_rest_type



199
200
201
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 199

def rest_type_name=(v)
  @rest_type_name = v.to_s
end