Sha256: 36773672d32557edd3b95477377b2ff69ea39845743dd931cf7b2fc25f1511cf

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true

module Sbmt
  module Strangler
    module Configurable
      def option(*hash)
        case hash
        in [*attributes, Hash => options]
        in [*attributes]
          options = {}
        end

        attributes.each do |attribute|
          define_method :"#{attribute}=" do |value|
            instance_variable_set(:"@#{attribute}", value)
          end

          define_method attribute.to_s do
            value = instance_variable_get(:"@#{attribute}")
            return value if value

            if options[:default_from]
              value = send(options[:default_from])&.public_send(attribute)
            end

            value || options[:default]
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sbmt-strangler-0.9.1 lib/sbmt/strangler/configurable.rb