lib/eco/api/common/loaders/use_case.rb in eco-helpers-2.6.4 vs lib/eco/api/common/loaders/use_case.rb in eco-helpers-2.7.0

- old
+ new

@@ -5,28 +5,32 @@ class UseCase < Eco::API::Common::Loaders::CaseBase class << self # @return [Symbol] the `type` of usecase (i.e. `:sync`, `:transform`, `:import`, `:other`) def type(value = nil) unless value - return @type || raise("You should specify a type of case [:sync, :transform, :import, :other] for #{self}") + msg = "You should specify a type of case " + msg << "[:sync, :transform, :import, :other] for #{self}" + return @type || (raise msg) end @type = value end def cli! cli&.apply! end def cli(cli_class = nil) if cli_class.is_a?(Class) - raise ArgumentError, "cli_class should inherit from Eco::API::UseCases::Cli" unless cli_class < Eco::API::UseCases::Cli + msg = "cli_class should inherit from Eco::API::UseCases::Cli" + raise ArgumentError, msg unless cli_class < Eco::API::UseCases::Cli + @cli = cli_class elsif cli_class.nil? return @cli if instance_variable_defined?(:@cli) && !@cli.nil? # try to see if it's namespaced after the use case it provisions cli integration begin - try_class = [self.to_s, 'Cli'].join('::') + try_class = [to_s, 'Cli'].join('::') @cli = Kernel.const_get(try_class) rescue NameError nil end else @@ -35,21 +39,23 @@ end end inheritable_class_vars :type, :cli - def initialize(usecases) - raise "Expected Eco::API::UseCases. Given #{usecases.class}" unless usecases.is_a?(Eco::API::UseCases) - usecases.define(self.name, type: self.type, &self.method(:main)) + def initialize(usecases) # rubocop:disable Lint/MissingSuper + msg = "Expected Eco::API::UseCases. Given #{usecases.class}" + raise msg unless usecases.is_a?(Eco::API::UseCases) + + usecases.define(name, type: type, &method(:main)) end # The parameters of this method will depend on the `type` of usecase. # @param entries [Eco::API::Common::People::Entries] the input entries with the data. # @param people [Eco::API::Organization::People] the people in the queue of the current `job` # @param session [Eco::API::Session] the current session where the usecase kicks in. # @param options [Hash] the options that modify the case behaviour or bring some dependencies. # @param usecase [Eco::API::Policies::Policy] the `usecase` instance object. - def main(entries, people, session, options, usecase) + def main(entries, people, session, options, usecase) # rubocop:disable Lint/UnusedMethodArgument raise "You should implement this method" end def type self.class.type