lib/snfoil/context.rb in snfoil-context-0.0.1 vs lib/snfoil/context.rb in snfoil-context-0.0.2

- old
+ new

@@ -36,15 +36,23 @@ class_methods do def action(name, with: nil, &block) raise SnFoil::Context::Error, "action #{name} already defined for #{self.name}" if (@defined_actions ||= []).include?(name) @defined_actions << name - setup_hooks(name) + define_workflow_hooks(name) define_action_primary(name, with, block) end end + def run_action_group(group_name, **options) + hooks = self.class.instance_variable_get("@#{group_name}_hooks") || [] + options = hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } + options = send(group_name, **options) if respond_to?(group_name) + + options + end + private # rubocop:disable reason: These are builder/mapping methods that are just too complex to simplify without # making them more complex. If anyone has a better way please let me know class_methods do # rubocop:disable Metrics/BlockLength @@ -64,11 +72,11 @@ end run_action_group(format('after_%s', name), **options) end end - def setup_hooks(name) + def define_workflow_hooks(name) hook_builder('setup_%s', name) hook_builder('before_%s', name) hook_builder('after_%s_success', name) hook_builder('after_%s_failure', name) hook_builder('after_%s', name) @@ -95,16 +103,8 @@ def run_action_primary(method, block, **options) return send(method, **options) if method instance_exec options, &block - end - - def run_action_group(group_name, **options) - options = self.class.instance_variable_get("@#{group_name}_hooks") - .reduce(options) { |opts, hook| run_hook(hook, opts) } - options = send(group_name, **options) if respond_to?(group_name) - - options end end end