Class: SimpleService::ValidatesCommandsProperlyInherit

Inherits:
Command
  • Object
show all
Defined in:
lib/simple_service/commands/validates_commands_properly_inherit.rb

Instance Attribute Summary

Attributes inherited from Command

#context

Instance Method Summary collapse

Methods inherited from Command

#initialize

Methods included from ServiceBase::ClassMethods

#expects, #get_expects, #get_returns, #returns, #skip_validation

Methods included from ServiceBase::InstanceMethods

#all_context_keys, #define_getters_and_setters, #expects, #failed?, #failure!, #find_specified_return_keys, #organizer?, #return_context_with_success_status, #returns, #setup_call_chain, #skip_validation, #successful?, #symbolize_context_keys

Constructor Details

This class inherits a constructor from SimpleService::Command

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/simple_service/commands/validates_commands_properly_inherit.rb', line 8

def call
  # valid commands inherit from Command and do not inherit from service
  # reject all valid commands and anything left over is invalid
  invalid_commands = provided_commands.to_a.reject do |command|
    command.ancestors.include?(SimpleService::Command) ||
    command.ancestors.include?(SimpleService::Organizer)
  end

  if invalid_commands.any?
    error_msg = invalid_commands.join(', ') +
      ' - must inherit from SimpleService::Command'
    raise SimpleService::CommandParentClassInvalidError, error_msg
  end
end