Class: Yes::Core::Aggregate::Dsl::CommandShortcutExpander
- Inherits:
-
Object
- Object
- Yes::Core::Aggregate::Dsl::CommandShortcutExpander
- Defined in:
- lib/yes/core/aggregate/dsl/command_shortcut_expander.rb
Overview
Class which converts attributes passed to Yes::Core::Aggregate::command in shorthand form to list of attributes and commands to define
Defined Under Namespace
Classes: AttributeSpecification, CommandSpecification, ExpandedCommandShortcut, InvalidShortcut
Constant Summary collapse
- SPECIAL_CASE_NAMES =
{ change: :change, enable: :enable, activate: :enable, publish: :publish }.freeze
Instance Attribute Summary collapse
- #args ⇒ Object readonly
- #block ⇒ Object readonly
- #kwargs ⇒ Object readonly
Class Method Summary collapse
-
.base_case?(*args, **kwargs, &block) ⇒ Boolean
Detects basic usage of command invocation, so the aggregate knows it’s not a shortcut.
Instance Method Summary collapse
-
#call ⇒ ExpandedCommandShortcut
Expands shortcut to Data object with list of attributes and commands.
-
#initialize(*args, **kwargs, &block) ⇒ CommandShortcutExpander
constructor
Takes all parameters passed to command invocation.
Constructor Details
#initialize(*args, **kwargs, &block) ⇒ CommandShortcutExpander
Takes all parameters passed to command invocation
48 49 50 51 52 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 48 def initialize(*args, **kwargs, &block) @args = args @kwargs = kwargs @block = block end |
Instance Attribute Details
#args ⇒ Object (readonly)
39 40 41 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 39 def args @args end |
#block ⇒ Object (readonly)
39 40 41 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 39 def block @block end |
#kwargs ⇒ Object (readonly)
39 40 41 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 39 def kwargs @kwargs end |
Class Method Details
.base_case?(*args, **kwargs, &block) ⇒ Boolean
Detects basic usage of command invocation, so the aggregate knows it’s not a shortcut
34 35 36 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 34 def base_case?(*args, **kwargs, &block) args.size == 1 && kwargs.empty? && block.present? end |
Instance Method Details
#call ⇒ ExpandedCommandShortcut
Expands shortcut to Data object with list of attributes and commands
generate
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 61 def call case args in [[Symbol, Symbol], Symbol] handle_toggle_commands in [Symbol => name, *] raise InvalidShortcut unless SPECIAL_CASE_NAMES.include?(name) send(:"handle_#{SPECIAL_CASE_NAMES[name]}_command") else raise InvalidShortcut end end |