Sha256: afe665ecd53d96225253c2fd1ebd004453100b10969e63ccfeaef55f5fa29bdd

Contents?: true

Size: 660 Bytes

Versions: 3

Compression:

Stored size: 660 Bytes

Contents

# frozen_string_literal: true

module ImmutableStructExRedactable
  module RedactedAccessible
    class << self
      def included(base)
        base.extend ClassModules
      end
    end

    module ClassModules
      def redacted_accessible_module_for(hash:, config:)
        Module.new do
          config.redacted.each do |attr|
            unredacted_attr_method = "unredacted_#{attr}"
            code = <<~CODE
              def #{unredacted_attr_method}
                "#{hash[attr]}"
              end
              private :#{unredacted_attr_method}
            CODE
            class_eval code
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immutable_struct_ex_redactable-1.2.2 lib/immutable_struct_ex_redactable/redacted_accessible.rb
immutable_struct_ex_redactable-1.2.1 lib/immutable_struct_ex_redactable/redacted_accessible.rb
immutable_struct_ex_redactable-1.2.0 lib/immutable_struct_ex_redactable/redacted_accessible.rb