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



281
282
283
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 281

def clear_registered_interfaces()
  @registered_interfaces = []
end

#default_rest_argObject



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

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

#default_rest_has_typeObject



139
140
141
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 139

def default_rest_has_type
  false
end

#default_rest_interface_nameObject



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

def default_rest_interface_name
  rest_name
end

#default_rest_keyObject



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

def default_rest_key
  rest_name.chomp("s")
end

#default_rest_labelObject



93
94
95
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 93

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

#default_rest_nameObject



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

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

#default_rest_plural_labelObject



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

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

#default_rest_type_argObject



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

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

#default_rest_type_interface_nameObject



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

def default_rest_type_interface_name
  rest_type_name
end

#default_rest_type_keyObject



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

def default_rest_type_key
  rest_type_name.chomp("s")
end

#default_rest_type_labelObject



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

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

#default_rest_type_nameObject



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

def default_rest_type_name
  rest_key + "_types"
end

#default_rest_type_plural_labelObject



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

def default_rest_type_plural_label
  #rest_type_name.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
  rest_type_label.to_s.pluralize
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



247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 247

def register_interfaces(*interfaces)
  @registered_interfaces ||= []
  interfaces.flatten.each do |it|
    @registered_interfaces << it.to_sym
  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



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

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]



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

def rest_arg
  @rest_arg || default_rest_arg
end

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



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

def rest_arg=(v)
  @rest_arg = v
end

#rest_has_typeObject

rest_has_type indicates a resource has a type. default is false



135
136
137
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 135

def rest_has_type
  @rest_has_type == true
end

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



143
144
145
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 143

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”



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

def rest_interface_name
  @rest_interface_name || default_rest_interface_name
end

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



128
129
130
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 128

def rest_interface_name=(v)
  @rest_interface_name = v
end

#rest_keyObject

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



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

def rest_key
  @rest_key || default_rest_key
end

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



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

def rest_key=(v)
  @rest_key = v
end

#rest_labelObject

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



89
90
91
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 89

def rest_label
  @rest_label || default_rest_label
end

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



97
98
99
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 97

def rest_label=(v)
  @rest_label = v
end

#rest_nameObject

rest_name is the plural name of the rest command resource eg. NeatThingsCommand 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 `-`.



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

def rest_name
  @rest_name || default_rest_name
end

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



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

def rest_name=(v)
  @rest_name = v
end

#rest_plural_labelObject

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



104
105
106
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 104

def rest_plural_label
  @rest_plural_label || default_rest_plural_label
end

#rest_plural_label=(v) ⇒ Object Also known as: set_rest_plural_label



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

def rest_plural_label=(v)
  @rest_plural_label = v
end

#rest_type_argObject



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

def rest_type_arg
  @rest_type_arg || default_rest_type_arg
end

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



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

def rest_type_arg=(v)
  @rest_type_arg = v
end

#rest_type_interface_nameObject

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



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

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



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

def rest_type_interface_name=(v)
  @rest_type_interface_name = v
end

#rest_type_keyObject

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



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

def rest_type_key
  @rest_type_key || default_rest_type_key
end

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



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

def rest_type_key=(v)
  @rest_type_key = v
end

#rest_type_labelObject

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



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

def rest_type_label
  @rest_type_label || default_rest_type_label
end

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



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

def rest_type_label=(v)
  @rest_type_label = v
end

#rest_type_nameObject

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



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

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



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

def rest_type_name=(v)
  @rest_type_name = v
end

#rest_type_plural_labelObject

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



214
215
216
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 214

def rest_type_plural_label
  @rest_type_plural_label || default_rest_type_plural_label
end

#rest_type_plural_label=(v) ⇒ Object Also known as: set_rest_type_plural_label



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

def rest_type_plural_label=(v)
  @rest_type_plural_label = v
end