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
TODO - revisit.
- #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.
3 4 5 6 |
# File 'lib/objects/registry/command/group.rb', line 3 def initialize(node) @all_commands = {} @node = node end |
Instance Attribute Details
#all_commands ⇒ Object (readonly)
Returns the value of attribute all_commands.
8 9 10 |
# File 'lib/objects/registry/command/group.rb', line 8 def all_commands @all_commands end |
Instance Method Details
#<<(command) ⇒ Object
10 11 12 |
# File 'lib/objects/registry/command/group.rb', line 10 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
30 31 32 |
# File 'lib/objects/registry/command/group.rb', line 30 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
18 19 20 |
# File 'lib/objects/registry/command/group.rb', line 18 def console_method_name_exists?(proposed_name) user_registered_console_command_names.include?(proposed_name) end |
#has_commands? ⇒ Boolean
14 15 16 |
# File 'lib/objects/registry/command/group.rb', line 14 def has_commands? all_commands.keys.any? end |
#in_console_session? ⇒ Boolean
47 48 49 |
# File 'lib/objects/registry/command/group.rb', line 47 def in_console_session? ::Bcome::System::Local.instance.in_console_session? end |
#item_spacing(item) ⇒ Object
34 35 36 37 |
# File 'lib/objects/registry/command/group.rb', line 34 def item_spacing(item) raise ::Bcome::Exception::InvalidRegistryCommandNameLength.new "command '#{item}' exceeds length limit of #{}" if item.length > "\s" * ( - item.length) end |
#menu_item_spacing_length ⇒ Object
39 40 41 |
# File 'lib/objects/registry/command/group.rb', line 39 def 16 end |
#pretty_print ⇒ Object
TODO - revisit. This is a mess
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/objects/registry/command/group.rb', line 51 def pretty_print ## TODO - revisit. This is a mess 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 = in_console_session? ? command_key.to_s : "bcome #{@node.keyed_namespace.empty? ? '' : "#{@node.keyed_namespace}:"}#{command_key}" 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" + 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
43 44 45 |
# File 'lib/objects/registry/command/group.rb', line 43 def tab_spacing "\s" * 3 end |
#user_registered_console_command_names ⇒ Object
22 23 24 |
# File 'lib/objects/registry/command/group.rb', line 22 def user_registered_console_command_names user_registered_console_commands.collect(&:console_command) end |
#user_registered_console_commands ⇒ Object
26 27 28 |
# File 'lib/objects/registry/command/group.rb', line 26 def user_registered_console_commands all_commands.collect { |_group, commands| commands }.flatten end |