Sha256: 54acfd2dd1a1eed05c2d81039522f1b068181a04688c5e7e38da07c236666e48
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
# frozen_string_literal: true # This class defines settings for step module Light module Services module Settings class Step # Getters attr_reader :name, :always def initialize(name, service_class, opts = {}) @name = name @service_class = service_class @if = opts[:if] @unless = opts[:unless] @always = opts[:always] if @if && @unless raise Light::Services::TwoConditions, "#{service_class} `if` and `unless` cannot be specified " \ "for the step `#{name}` at the same time" end end def run(instance, benchmark: false) return false unless run?(instance) if instance.respond_to?(name, true) if benchmark time = Benchmark.ms do instance.send(name) end instance.log "⏱️ Step #{name} took #{time}ms" else instance.send(name) end true else raise Light::Services::NoStepError, "Cannot find step `#{name}` in service `#{@service_class}`" end end private def run?(instance) if @if check_condition(@if, instance) elsif @unless !check_condition(@unless, instance) else true end end def check_condition(condition, instance) case condition when Symbol instance.send(condition) when Proc condition.call else raise Light::Services::Error, "#{@service_class} condition should be a Symbol or Proc " \ "for the step `#{@name}` (currently: #{condition.class})" end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
light-services-2.0.0.rc2 | lib/light/services/settings/step.rb |
light-services-2.0.0.rc1 | lib/light/services/settings/step.rb |