Sha256: 3ae8a05b52f7b1567139a3c75e42ab7812771a18fce66036216bee84d98153b3

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Pacer
  module FunctionResolver
    class << self
      def clear_cache
        @lookup_path = nil
      end

      def function(args)
        lookup_path.each do |key, map, extension|
          if value = args[key]
            function = map.fetch(value, value.is_a?(Module) && value)
            return [function, extension] if function
          end
        end
        nil
      end

      def lookup_path
        @lookup_path ||= [
          [:filter, filter_map, nil],
          [:transform, transform_map, nil],
          [:side_effect, side_effect_map, Pacer::Core::SideEffect]
        ]
      end

      def filter_map
        Hash[Pacer::Filter.constants.map { |name| [symbolize_module_name(name), Pacer::Filter.const_get(name)] }]
      end

      def side_effect_map
        Hash[Pacer::SideEffect.constants.map { |name| [symbolize_module_name(name), Pacer::SideEffect.const_get(name)] }]
      end

      def transform_map
        Hash[Pacer::Transform.constants.map { |name| [symbolize_module_name(name), Pacer::Transform.const_get(name)] }]
      end

      def symbolize_module_name(name)
        name.to_s.sub(/(Filter|SideEffect|Transform)$/, '').gsub(/([a-z])([A-Z])/, "\\1_\\2").downcase.to_sym
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pacer-0.9.1.1-java lib/pacer/function_resolver.rb