Sha256: d53e529246cabdd37a23b2df7fe19d9ada536fbfd423e1c43b98bb250278f1bf

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module Fluxo
  class Operation
    module Attributes
      def self.included(klass)
        klass.extend(ClassMethods)
      end

      module ClassMethods
        attr_reader :validations_proxy

        # When set to true, the operation will not validate the transient_attributes defition during the flow step execution.
        attr_writer :strict_transient_attributes

        # When set to true, the operation will not validate attributes definition before calling the operation.
        attr_writer :strict_attributes

        def strict_attributes?
          return @strict_attributes if defined?(@strict_attributes)

          Fluxo.config.strict_attributes
        end

        def strict_transient_attributes?
          return @strict_transient_attributes if defined?(@strict_transient_attributes)

          Fluxo.config.strict_transient_attributes
        end

        def validations
          raise NotImplementedError, "ActiveModel is not defined to use validations."
        end

        def attribute_names
          @attribute_names ||= []
        end

        def transient_attribute_names
          @transient_attribute_names ||= []
        end

        def attributes(*names)
          @attribute_names ||= []
          names = names.map(&:to_sym) - @attribute_names
          @attribute_names.push(*names)
        end

        def transient_attributes(*names)
          @transient_attribute_names ||= []
          names = names.map(&:to_sym) - @transient_attribute_names
          @transient_attribute_names.push(*names)
        end

        def attribute?(key)
          return false unless key

          attribute_names.include?(key.to_sym)
        end

        def transient_attribute?(key)
          return false unless key

          transient_attribute_names.include?(key.to_sym)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluxo-0.2.1 lib/fluxo/operation/attributes.rb
fluxo-0.2.0 lib/fluxo/operation/attributes.rb