module SnFoil::Contexts::CreateContext
Public Instance Methods
after_create(method = nil, **options, &block)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 38 def after_create(method = nil, **options, &block) raise ArgumentError, '#after_create requires either a method name or a block' if method.nil? && block.nil? (@i_after_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] } end
after_create_failure(method = nil, **options, &block)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 50 def after_create_failure(method = nil, **options, &block) raise ArgumentError, '#after_create_failure requires either a method name or a block' if method.nil? && block.nil? (@i_after_create_failure_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] } end
after_create_failure_hooks()
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 103 def after_create_failure_hooks self.class.i_after_create_failure_hooks || [] end
after_create_hooks()
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 95 def after_create_hooks self.class.i_after_create_hooks || [] end
after_create_success(method = nil, **options, &block)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 44 def after_create_success(method = nil, **options, &block) raise ArgumentError, '#after_create_success requires either a method name or a block' if method.nil? && block.nil? (@i_after_create_success_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] } end
after_create_success_hooks()
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 99 def after_create_success_hooks self.class.i_after_create_success_hooks || [] end
before_create(method = nil, **options, &block)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 32 def before_create(method = nil, **options, &block) raise ArgumentError, '#before_create requires either a method name or a block' if method.nil? && block.nil? (@i_before_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] } end
before_create_hooks()
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 91 def before_create_hooks self.class.i_before_create_hooks || [] end
create(params:, entity: nil, **options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 22 def create(params:, entity: nil, **options) new(entity).create(**options, params: params) end
setup_create(method = nil, **options, &block)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 26 def setup_create(method = nil, **options, &block) raise ArgumentError, '#setup_create requires either a method name or a block' if method.nil? && block.nil? (@i_setup_create_hooks ||= []) << { method: method, block: block, if: options[:if], unless: options[:unless] } end
setup_create_hooks()
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 87 def setup_create_hooks self.class.i_setup_create_hooks || [] end
Private Instance Methods
after_create_save(**options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 136 def after_create_save(**options) options = after_change(**options) options = after_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } options = after_create(**options) after_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } end
after_create_save_failure(**options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 150 def after_create_save_failure(**options) options = after_change_failure(**options) options = after_change_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } options = after_create_failure(**options) after_create_failure_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } end
after_create_save_success(**options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 143 def after_create_save_success(**options) options = after_change_success(**options) options = after_change_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } options = after_create_success(**options) after_create_success_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } end
before_create_save(**options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 129 def before_create_save(**options) options = before_change(**options) options = before_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } options = before_create(**options) before_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } end
before_setup_create_object(**options)
click to toggle source
# File lib/sn_foil/contexts/create_context.rb, line 109 def before_setup_create_object(**options) options = setup_change(**options) options = setup_change_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } options = setup_create(**options) setup_create_hooks.reduce(options) { |opts, hook| run_hook(hook, opts) } end
create_hooks(options)
click to toggle source
This method is private to help protect the order of execution of hooks
# File lib/sn_foil/contexts/create_context.rb, line 117 def create_hooks(options) options = before_create_save(**options) save_successful = options[:object].save options[:object] = unwrap_object(options[:object]) options = if save_successful after_create_save_success(**options) else after_create_save_failure(**options) end after_create_save(**options) end