Sha256: 1be7a71a4089385a34f2a2e0839c65480843a30b212bc29d5baf5e248449d792
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 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) return false unless run?(instance) if instance.respond_to?(name, true) instance.send(name) 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.public_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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
light-services-2.0.0.beta1 | lib/light/services/settings/step.rb |