Class: Yes::Core::Aggregate::Dsl::CommandShortcutExpander

Inherits:
Object
  • Object
show all
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

Since:

  • 0.1.0

Defined Under Namespace

Classes: AttributeSpecification, CommandSpecification, ExpandedCommandShortcut, InvalidShortcut

Constant Summary collapse

SPECIAL_CASE_NAMES =

Since:

  • 0.1.0

{
  change: :change,
  enable: :enable,
  activate: :enable,
  publish: :publish
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, **kwargs, &block) ⇒ CommandShortcutExpander

Takes all parameters passed to command invocation

Parameters:

  • *args (Array<Object>)
  • **kwargs (Hash<Object, Object>)
  • &block (Proc)

Since:

  • 0.1.0



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

#argsObject (readonly)

Since:

  • 0.1.0



39
40
41
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 39

def args
  @args
end

#blockObject (readonly)

Since:

  • 0.1.0



39
40
41
# File 'lib/yes/core/aggregate/dsl/command_shortcut_expander.rb', line 39

def block
  @block
end

#kwargsObject (readonly)

Since:

  • 0.1.0



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

Parameters:

  • *args (Array<Object>)
  • **kwargs (Hash<Object, Object>)
  • &block (Proc)

Returns:

  • (Boolean)

Since:

  • 0.1.0



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

#callExpandedCommandShortcut

Expands shortcut to Data object with list of attributes and commands

generate

Returns:

Raises:

Since:

  • 0.1.0



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