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



298
299
300
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 298

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



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

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



204
205
206
207
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 204

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

#default_rest_type_interface_nameObject



251
252
253
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 251

def default_rest_type_interface_name
  rest_type_name
end

#default_rest_type_keyObject



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

def default_rest_type_key
  rest_type_name.chomp("s")
end

#default_rest_type_labelObject



220
221
222
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 220

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

#default_rest_type_label_pluralObject



235
236
237
238
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 235

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



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

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



264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 264

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



283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 283

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
  @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
  @rest_has_name != nil ? @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



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

def rest_has_type
  @rest_has_type == true
end

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



160
161
162
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 160

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
  @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
  @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
  @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
  @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
  @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_type_argObject



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

def rest_type_arg
  @rest_type_arg || default_rest_type_arg
end

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



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

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”



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

def 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



255
256
257
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 255

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”



186
187
188
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 186

def rest_type_key
  @rest_type_key || default_rest_type_key
end

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



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

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”



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

def rest_type_label
  @rest_type_label || default_rest_type_label
end

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



224
225
226
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 224

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”



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

def 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



240
241
242
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 240

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



169
170
171
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 169

def 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



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

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