lib/command.rb in g2_command-0.2.0 vs lib/command.rb in g2_command-0.3.0
- old
+ new
@@ -9,15 +9,20 @@
require 'command/interrupt'
module Command
extend ActiveSupport::Concern
+ # rubocop:disable Metrics/BlockLength
included do
extend Dry::Initializer
include Dry::Monads[:result]
include ActiveModel::Validations
+ def initialize(inputs = {})
+ super(Command::InputMiddleware.call(inputs))
+ end
+
def execute
raise NotImplementedError
end
def run
@@ -42,22 +47,17 @@
def inputs
self.class.dry_initializer.attributes(self)
end
end
+ # rubocop:enable Metrics/BlockLength
class_methods do
def run(inputs = {})
- new(normalize_inputs(inputs)).run
+ new(inputs).run
end
def run!(inputs = {})
run(inputs).value!
- end
-
- private
-
- def normalize_inputs(inputs)
- Command::InputMiddleware.call(inputs)
end
end
end