Sha256: 62e7716ccb3de88ab4509ff20e609a84e6493a63201ab9cd464d648d88204182
Contents?: true
Size: 763 Bytes
Versions: 4
Compression:
Stored size: 763 Bytes
Contents
# frozen_string_literal: true require 'hashie/mash' module Chamber module Filters class NamespaceFilter def self.execute(**args) new(**args).__send__(:execute) end attr_accessor :data, :namespaces def initialize(data:, namespaces:, **_args) self.data = Hashie::Mash.new(data) self.namespaces = namespaces end protected def execute if data_is_namespaced? namespaces.each_with_object(Hashie::Mash.new) do |namespace, filtered_data| filtered_data.merge!(data[namespace]) if data[namespace] end else Hashie::Mash.new(data) end end private def data_is_namespaced? @data_is_namespaced ||= data.keys.any? { |key| namespaces.include? key.to_s } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems