Module: Morpheus::Cli::RestCommand::ClassMethods
- Defined in:
- lib/morpheus/cli/mixins/rest_command.rb
Instance Method Summary collapse
-
#clear_registered_interfaces ⇒ Object
clear the list of registered interfaces, perhaps useful in a command subclass.
- #default_rest_arg ⇒ Object
- #default_rest_has_type ⇒ Object
- #default_rest_interface_name ⇒ Object
- #default_rest_key ⇒ Object
- #default_rest_label ⇒ Object
- #default_rest_label_plural ⇒ Object
- #default_rest_name ⇒ Object
- #default_rest_type_arg ⇒ Object
- #default_rest_type_interface_name ⇒ Object
- #default_rest_type_key ⇒ Object
- #default_rest_type_label ⇒ Object
- #default_rest_type_label_plural ⇒ Object
- #default_rest_type_name ⇒ Object
-
#register_interfaces(*interfaces) ⇒ Object
(also: #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.
-
#registered_interfaces ⇒ Object
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.
-
#rest_arg ⇒ Object
rest_arg is a label for the arg in the command usage eg.
- #rest_arg=(v) ⇒ Object (also: #set_rest_arg)
-
#rest_has_type ⇒ Object
rest_has_type indicates a resource has a type.
- #rest_has_type=(v) ⇒ Object (also: #set_rest_has_type)
-
#rest_interface_name ⇒ Object
rest_interface_name is the interface name for the resource.
- #rest_interface_name=(v) ⇒ Object (also: #set_rest_interface_name)
-
#rest_key ⇒ Object
rest_key is the singular name of the resource eg.
- #rest_key=(v) ⇒ Object (also: #set_rest_key)
-
#rest_label ⇒ Object
rest_label is the capitalized resource label eg.
- #rest_label=(v) ⇒ Object (also: #set_rest_label)
-
#rest_label_plural ⇒ Object
the plural version of the label eg.
- #rest_label_plural=(v) ⇒ Object (also: #set_rest_label_plural)
-
#rest_name ⇒ Object
rest_name is the plural name of the rest command resource eg.
- #rest_name=(v) ⇒ Object (also: #set_rest_name)
- #rest_type_arg ⇒ Object
- #rest_type_arg=(v) ⇒ Object (also: #set_rest_type_arg)
-
#rest_type_interface_name ⇒ Object
the name of the default interface, matches the rest name eg.
- #rest_type_interface_name=(v) ⇒ Object (also: #set_rest_type_interface_name)
-
#rest_type_key ⇒ Object
rest_type_key is the singular name of the resource eg.
- #rest_type_key=(v) ⇒ Object (also: #set_rest_type_key)
-
#rest_type_label ⇒ Object
rest_type_label is the capitalized resource label eg.
- #rest_type_label=(v) ⇒ Object (also: #set_rest_type_label)
-
#rest_type_label_plural ⇒ Object
the plural version of the label eg.
- #rest_type_label_plural=(v) ⇒ Object (also: #set_rest_type_label_plural)
-
#rest_type_name ⇒ Object
rest_type_name is the rest_name for the type, only applicable if rest_has_type.
- #rest_type_name=(v) ⇒ Object (also: #set_rest_type_name, #set_rest_type)
Instance Method Details
#clear_registered_interfaces ⇒ Object
clear the list of registered interfaces, perhaps useful in a command subclass
282 283 284 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 282 def clear_registered_interfaces() @registered_interfaces = [] end |
#default_rest_arg ⇒ Object
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_type ⇒ Object
140 141 142 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 140 def default_rest_has_type false end |
#default_rest_interface_name ⇒ Object
125 126 127 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 125 def default_rest_interface_name rest_name end |
#default_rest_key ⇒ Object
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_label ⇒ Object
94 95 96 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 94 def default_rest_label rest_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ") end |
#default_rest_label_plural ⇒ Object
109 110 111 112 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 109 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_name ⇒ Object
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_arg ⇒ Object
188 189 190 191 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 188 def default_rest_type_arg # rest_type_key.gsub("_", " ") # "[" + rest_key.gsub("_", " ") + "]" "type" # [type] end |
#default_rest_type_interface_name ⇒ Object
235 236 237 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 235 def default_rest_type_interface_name rest_type_name end |
#default_rest_type_key ⇒ Object
174 175 176 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 174 def default_rest_type_key rest_type_name.chomp("s") end |
#default_rest_type_label ⇒ Object
204 205 206 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 204 def default_rest_type_label rest_type_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ") end |
#default_rest_type_label_plural ⇒ Object
219 220 221 222 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 219 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_name ⇒ Object
157 158 159 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 157 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
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 248 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_interfaces ⇒ Object
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
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 267 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_arg ⇒ Object
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_type ⇒ Object
rest_has_type indicates a resource has a type. default is false
136 137 138 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 136 def rest_has_type @rest_has_type == true end |
#rest_has_type=(v) ⇒ Object Also known as: set_rest_has_type
144 145 146 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 144 def rest_has_type=(v) @rest_has_type = !!v end |
#rest_interface_name ⇒ Object
rest_interface_name is the interface name for the resource. eg. “neat_things”
121 122 123 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 121 def rest_interface_name @rest_interface_name || default_rest_interface_name end |
#rest_interface_name=(v) ⇒ Object Also known as: set_rest_interface_name
129 130 131 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 129 def rest_interface_name=(v) @rest_interface_name = v.to_s end |
#rest_key ⇒ Object
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_label ⇒ Object
rest_label is the capitalized resource label eg. “Neat Thing”
90 91 92 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 90 def rest_label @rest_label || default_rest_label end |
#rest_label=(v) ⇒ Object Also known as: set_rest_label
98 99 100 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 98 def rest_label=(v) @rest_label = v.to_s end |
#rest_label_plural ⇒ Object
the plural version of the label eg. “Neat Things”
105 106 107 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 105 def rest_label_plural @rest_label_plural || default_rest_label_plural end |
#rest_label_plural=(v) ⇒ Object Also known as: set_rest_label_plural
114 115 116 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 114 def rest_label_plural=(v) @rest_label_plural = v.to_s end |
#rest_name ⇒ Object
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 `-`.
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_arg ⇒ Object
184 185 186 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 184 def rest_type_arg @rest_type_arg || default_rest_type_arg end |
#rest_type_arg=(v) ⇒ Object Also known as: set_rest_type_arg
193 194 195 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 193 def rest_type_arg=(v) @rest_type_arg = v.to_s end |
#rest_type_interface_name ⇒ Object
the name of the default interface, matches the rest name eg. “neat_things”
231 232 233 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 231 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
239 240 241 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 239 def rest_type_interface_name=(v) @rest_type_interface_name = v.to_s end |
#rest_type_key ⇒ Object
rest_type_key is the singular name of the resource eg. “neat_thing”
170 171 172 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 170 def rest_type_key @rest_type_key || default_rest_type_key end |
#rest_type_key=(v) ⇒ Object Also known as: set_rest_type_key
178 179 180 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 178 def rest_type_key=(v) @rest_type_key = v.to_s end |
#rest_type_label ⇒ Object
rest_type_label is the capitalized resource label eg. “Neat Thing”
200 201 202 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 200 def rest_type_label @rest_type_label || default_rest_type_label end |
#rest_type_label=(v) ⇒ Object Also known as: set_rest_type_label
208 209 210 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 208 def rest_type_label=(v) @rest_type_label = v.to_s end |
#rest_type_label_plural ⇒ Object
the plural version of the label eg. “Neat Things”
215 216 217 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 215 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
224 225 226 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 224 def rest_type_label_plural=(v) @rest_type_label_plural = v.to_s end |
#rest_type_name ⇒ Object
rest_type_name is the rest_name for the type, only applicable if rest_has_type
153 154 155 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 153 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
161 162 163 |
# File 'lib/morpheus/cli/mixins/rest_command.rb', line 161 def rest_type_name=(v) @rest_type_name = v.to_s end |