Sha256: b8f6ab8d460e03f588350c2fb93975ce0cb3cba21dc71276d712fa8553cd55f4

Contents?: true

Size: 1.05 KB

Versions: 46

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Ariadne
  # :nodoc:
  module Forms
    # :nodoc:
    module Utils
      # Unfortunately this bug (https://github.com/ruby/ruby/pull/5646) prevents us from using
      # Ruby's native Module.const_source_location. Instead we have to fudge it by searching
      # for the file in the configured autoload paths. Doing so relies on Rails' autoloading
      # conventions, so it should work ok. Zeitwerk also has this information but lacks a
      # public API to map constants to source files.
      def const_source_location(class_name)
        return unless class_name

        # NOTE: underscore respects namespacing, i.e. will convert Foo::Bar to foo/bar.
        class_path = "#{class_name.underscore}.rb"

        ActiveSupport::Dependencies.autoload_paths.each do |autoload_path|
          absolute_path = File.join(autoload_path, class_path)
          return absolute_path if File.exist?(absolute_path)
        end

        nil
      end

      def classify(options)
        options
      end
    end

    Utils.extend(Utils)
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.92 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.91 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.90 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.89.1 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.89 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.88 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.87 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.9 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.8 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.7 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.6 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.5 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.4 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.3 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.2 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86.1 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.86 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.85 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.84 lib/ariadne/forms/utils.rb
ariadne_view_components-0.0.83.3 lib/ariadne/forms/utils.rb