Class: Gitlab::QuickActions::CommandDefinition
- Inherits:
-
Object
- Object
- Gitlab::QuickActions::CommandDefinition
- Defined in:
- lib/gitlab/quick_actions/command_definition.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action_block ⇒ Object
Returns the value of attribute action_block.
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#condition_block ⇒ Object
Returns the value of attribute condition_block.
-
#description ⇒ Object
Returns the value of attribute description.
-
#execution_message ⇒ Object
Returns the value of attribute execution_message.
-
#explanation ⇒ Object
Returns the value of attribute explanation.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
-
#parse_params_block ⇒ Object
Returns the value of attribute parse_params_block.
-
#types ⇒ Object
Returns the value of attribute types.
-
#warning ⇒ Object
Returns the value of attribute warning.
Instance Method Summary collapse
- #all_names ⇒ Object
- #available?(context) ⇒ Boolean
- #execute(context, arg) ⇒ Object
- #execute_message(context, arg) ⇒ Object
- #explain(context, arg) ⇒ Object
-
#initialize(name, attributes = {}) ⇒ CommandDefinition
constructor
A new instance of CommandDefinition.
- #noop? ⇒ Boolean
- #to_h(context) ⇒ Object
Constructor Details
#initialize(name, attributes = {}) ⇒ CommandDefinition
Returns a new instance of CommandDefinition.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 9 def initialize(name, attributes = {}) @name = name @aliases = attributes[:aliases] || [] @description = attributes[:description] || '' @warning = attributes[:warning] || '' @icon = attributes[:icon] || '' @explanation = attributes[:explanation] || '' @execution_message = attributes[:execution_message] || '' @params = attributes[:params] || [] @condition_block = attributes[:condition_block] @parse_params_block = attributes[:parse_params_block] @action_block = attributes[:action_block] @types = attributes[:types] || [] end |
Instance Attribute Details
#action_block ⇒ Object
Returns the value of attribute action_block
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def action_block @action_block end |
#aliases ⇒ Object
Returns the value of attribute aliases
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def aliases @aliases end |
#condition_block ⇒ Object
Returns the value of attribute condition_block
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def condition_block @condition_block end |
#description ⇒ Object
Returns the value of attribute description
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def description @description end |
#execution_message ⇒ Object
Returns the value of attribute execution_message
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def @execution_message end |
#explanation ⇒ Object
Returns the value of attribute explanation
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def explanation @explanation end |
#icon ⇒ Object
Returns the value of attribute icon
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def icon @icon end |
#name ⇒ Object
Returns the value of attribute name
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def name @name end |
#params ⇒ Object
Returns the value of attribute params
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def params @params end |
#parse_params_block ⇒ Object
Returns the value of attribute parse_params_block
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def parse_params_block @parse_params_block end |
#types ⇒ Object
Returns the value of attribute types
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def types @types end |
#warning ⇒ Object
Returns the value of attribute warning
6 7 8 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 6 def warning @warning end |
Instance Method Details
#all_names ⇒ Object
25 26 27 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 25 def all_names [name, *aliases] end |
#available?(context) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 33 def available?(context) return false unless valid_type?(context) return true unless condition_block context.instance_exec(&condition_block) end |
#execute(context, arg) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 58 def execute(context, arg) return unless executable?(context) count_commands_executed_in(context) execute_block(action_block, context, arg) end |
#execute_message(context, arg) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 66 def (context, arg) return unless executable?(context) if .respond_to?(:call) execute_block(, context, arg) else end end |
#explain(context, arg) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 40 def explain(context, arg) return unless available?(context) = if explanation.respond_to?(:call) execute_block(explanation, context, arg) else explanation end warning_text = if warning.respond_to?(:call) execute_block(warning, context, arg) else warning end warning.empty? ? : "#{} (#{warning_text})" end |
#noop? ⇒ Boolean
29 30 31 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 29 def noop? action_block.nil? end |
#to_h(context) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gitlab/quick_actions/command_definition.rb', line 76 def to_h(context) desc = description if desc.respond_to?(:call) desc = context.instance_exec(&desc) rescue '' end warn = warning if warn.respond_to?(:call) warn = context.instance_exec(&warn) rescue '' end prms = params if prms.respond_to?(:call) prms = Array(context.instance_exec(&prms)) rescue params end { name: name, aliases: aliases, description: desc, warning: warn, icon: icon, params: prms } end |