Module: ControllerCommands::Command

Defined in:
lib/controller_commands/command.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



44
45
46
# File 'lib/controller_commands/command.rb', line 44

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#errorsObject



57
58
59
# File 'lib/controller_commands/command.rb', line 57

def errors
  @result.messages
end

#initialize(incoming_params, context) ⇒ Object



48
49
50
51
# File 'lib/controller_commands/command.rb', line 48

def initialize(incoming_params, context)
  @incoming_params = incoming_params
  @context = context
end

#performObject



74
75
76
# File 'lib/controller_commands/command.rb', line 74

def perform
  self.class.perform(@context, validated_params)
end

#render_success(output) ⇒ Object



78
79
80
# File 'lib/controller_commands/command.rb', line 78

def render_success(output)
  self.class.execute_before_success_render(@context, output)
end

#success_messageObject



70
71
72
# File 'lib/controller_commands/command.rb', line 70

def success_message
  self.class.get_success_message
end

#validate_paramsObject



65
66
67
68
# File 'lib/controller_commands/command.rb', line 65

def validate_params
  @result = self.class.validate(@context, @incoming_params)
  @result.messages.count == 0
end

#validated?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/controller_commands/command.rb', line 53

def validated?
  !!@result
end

#validated_paramsObject



61
62
63
# File 'lib/controller_commands/command.rb', line 61

def validated_params
  @result.output
end