Class: ActiveCommand::Command
- Inherits:
-
Object
- Object
- ActiveCommand::Command
- Includes:
- Core, ActiveModel::Serializers::JSON, ActiveModel::Validations, Sidekiq::Worker
- Defined in:
- lib/active_command/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
- #perform(job_data) ⇒ Object
- #perform_now ⇒ Object
- #run ⇒ Object
- #to_params ⇒ Object (also: #to_hash)
Class Method Details
.from_json(json) ⇒ Object
11 12 13 14 15 |
# File 'lib/active_command/command.rb', line 11 def self.from_json(json) klass = self.new klass.from_json(json) klass end |
Instance Method Details
#execute ⇒ Object
39 40 41 |
# File 'lib/active_command/command.rb', line 39 def execute raise NotImplementedError, "#{self.class.name} does not implement an execute method" end |
#perform(job_data) ⇒ Object
26 27 28 29 |
# File 'lib/active_command/command.rb', line 26 def perform(job_data) self.from_json(job_data) self.perform_now end |
#perform_now ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/active_command/command.rb', line 31 def perform_now if self.valid? self.execute else raise ActiveCommand::CommandNotValidError, self.errors. end end |
#run ⇒ Object
22 23 24 |
# File 'lib/active_command/command.rb', line 22 def run self.class.perform_async self.to_params.to_json end |
#to_params ⇒ Object Also known as: to_hash
17 18 19 |
# File 'lib/active_command/command.rb', line 17 def to_params ActiveSupport::HashWithIndifferentAccess.new(attributes).delete_if { |k, v| v.nil? } end |