Class: ActiveCommand::Command

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, ActiveModel::Validations
Defined in:
lib/active_command/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json) ⇒ Object



7
8
9
10
11
# File 'lib/active_command/command.rb', line 7

def self.from_json(json)
  klass = self.new
  klass.from_json(json)
  klass
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/active_command/command.rb', line 26

def execute
  raise NotImplementedError, "#{self.class.name} does not implement an execute method"
end

#runObject



18
19
20
21
22
23
24
# File 'lib/active_command/command.rb', line 18

def run
  if self.valid?
    self.execute
  else
    raise ActiveCommand::CommandNotValidError, self.errors.full_messages
  end
end

#to_paramsObject Also known as: to_hash



13
14
15
# File 'lib/active_command/command.rb', line 13

def to_params
  ActiveSupport::HashWithIndifferentAccess.new(attributes).delete_if { |k, v| v.nil? }
end