Class: Bcome::Registry::Command::Group
- Inherits:
-
Object
- Object
- Bcome::Registry::Command::Group
- Defined in:
- lib/objects/registry/command/group.rb
Instance Attribute Summary collapse
-
#all_commands ⇒ Object
readonly
Returns the value of attribute all_commands.
Instance Method Summary collapse
- #<<(command) ⇒ Object
- #command_for_console_command_name(command_name) ⇒ Object
- #console_method_name_exists?(proposed_name) ⇒ Boolean
- #has_commands? ⇒ Boolean
- #in_console_session? ⇒ Boolean
-
#initialize(node) ⇒ Group
constructor
A new instance of Group.
- #item_spacing(item) ⇒ Object
- #menu_item_spacing_length ⇒ Object
- #pretty_print ⇒ Object
- #tab_spacing ⇒ Object
- #user_registered_console_command_names ⇒ Object
- #user_registered_console_commands ⇒ Object
Constructor Details
#initialize(node) ⇒ Group
Returns a new instance of Group.
5 6 7 8 |
# File 'lib/objects/registry/command/group.rb', line 5 def initialize(node) @all_commands = {} @node = node end |
Instance Attribute Details
#all_commands ⇒ Object (readonly)
Returns the value of attribute all_commands.
10 11 12 |
# File 'lib/objects/registry/command/group.rb', line 10 def all_commands @all_commands end |
Instance Method Details
#<<(command) ⇒ Object
12 13 14 |
# File 'lib/objects/registry/command/group.rb', line 12 def <<(command) all_commands[command.group] ? (all_commands[command.group] << command) : (all_commands[command.group] = [command]) end |
#command_for_console_command_name(command_name) ⇒ Object
32 33 34 |
# File 'lib/objects/registry/command/group.rb', line 32 def command_for_console_command_name(command_name) user_registered_console_commands.select { |command| command.console_command.to_sym == command_name }.first end |
#console_method_name_exists?(proposed_name) ⇒ Boolean
20 21 22 |
# File 'lib/objects/registry/command/group.rb', line 20 def console_method_name_exists?(proposed_name) user_registered_console_command_names.include?(proposed_name) end |
#has_commands? ⇒ Boolean
16 17 18 |
# File 'lib/objects/registry/command/group.rb', line 16 def has_commands? all_commands.keys.any? end |
#in_console_session? ⇒ Boolean
50 51 52 |
# File 'lib/objects/registry/command/group.rb', line 50 def in_console_session? ::Bcome::System::Local.instance.in_console_session? end |
#item_spacing(item) ⇒ Object
36 37 38 39 40 |
# File 'lib/objects/registry/command/group.rb', line 36 def item_spacing(item) raise ::Bcome::Exception::InvalidRegistryCommandNameLength, "command '#{item}' exceeds length limit of #{}" if item.length > "\s" * ( - item.length) end |
#menu_item_spacing_length ⇒ Object
42 43 44 |
# File 'lib/objects/registry/command/group.rb', line 42 def 16 end |
#pretty_print ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/objects/registry/command/group.rb', line 54 def pretty_print puts "\nRegistry commands".title + "\sfor #{@node.class} #{@node.keyed_namespace}".resource_value + "\n\n" all_commands.sort.each do |group_name, commands| puts tab_spacing + group_name.title + "\n\n" commands.each do |command| command_key = command.console_command description = command.description defaults = command.defaults puts tab_spacing + command_key.resource_key + item_spacing(command_key) + description.resource_value usage_string = if in_console_session? command_key.to_s else "bcome #{@node.keyed_namespace.empty? ? '' : "#{@node.keyed_namespace}:"}#{command_key}" end puts tab_spacing + ("\s" * ) + 'usage: '.instructional + usage_string if defaults.keys.any? defaults_usage = in_console_session? ? "\s#{defaults.collect { |key, _value| "\"#{key}=your-value\"" }.join(",\s")}" : "\s" + defaults.collect { |key, _value| "#{key}=your-value" }.join("\s") puts tab_spacing + ("\s" * ) + "defaults:\s".instructional + defaults.collect { |k, v| "#{k}=#{v}" }.join(', ') puts tab_spacing + ("\s" * ) + "override:\s".instructional + usage_string + defaults_usage end puts "\n" end puts "\n" end nil end |
#tab_spacing ⇒ Object
46 47 48 |
# File 'lib/objects/registry/command/group.rb', line 46 def tab_spacing "\s" * 3 end |
#user_registered_console_command_names ⇒ Object
24 25 26 |
# File 'lib/objects/registry/command/group.rb', line 24 def user_registered_console_command_names user_registered_console_commands.collect(&:console_command) end |
#user_registered_console_commands ⇒ Object
28 29 30 |
# File 'lib/objects/registry/command/group.rb', line 28 def user_registered_console_commands all_commands.collect { |_group, commands| commands }.flatten end |