Sha256: 28effb52a2f248fa3a2c6fc84e47a8ecc9ffe2ff02365f73c65eafdb202bbf15

Contents?: true

Size: 1.01 KB

Versions: 29

Compression:

Stored size: 1.01 KB

Contents

module Tins
  module DeepConstGet
    if ::Object.method(:const_defined?).arity == 1
      # :nocov:
      # We do not create coverage on 1.8
      def self.const_defined_in?(modul, constant)
        modul.const_defined?(constant)
      end
      # :nocov:
    else
      def self.const_defined_in?(modul, constant)
        modul.const_defined?(constant, false)
      end
    end

    def deep_const_get(path, start_module = Object)
      path.to_s.split('::').inject(start_module) do |p, c|
        case
        when c.empty?
          if start_module == Object
            Object
          else
            raise ArgumentError, "top level constants cannot be reached from"\
              " start module #{start_module.inspect}"
          end
        when ::Tins::DeepConstGet.const_defined_in?(p, c) then p.const_get(c)
        else
          begin
            p.const_missing(c)
          rescue NameError => e
            raise ArgumentError, "can't get const #{path}: #{e}"
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 28 versions & 3 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/deep_const_get.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/deep_const_get.rb
tdiary-5.0.8 vendor/bundle/gems/tins-0.13.2/lib/tins/deep_const_get.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/tins-0.13.2/lib/tins/deep_const_get.rb
tins-1.1.0 lib/tins/deep_const_get.rb
tins-1.0.1 lib/tins/deep_const_get.rb
tins-1.0.0 lib/tins/deep_const_get.rb
tins-0.13.2 lib/tins/deep_const_get.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/tins-0.13.1/lib/tins/deep_const_get.rb
tins-0.13.1 lib/tins/deep_const_get.rb
tins-0.13.0 lib/tins/deep_const_get.rb
tins-0.12.0 lib/tins/deep_const_get.rb
tins-0.11.0 lib/tins/deep_const_get.rb
tins-0.10.0 lib/tins/deep_const_get.rb
tins-0.9.0 lib/tins/deep_const_get.rb
tins-0.8.4 lib/tins/deep_const_get.rb
tins-0.8.3 lib/tins/deep_const_get.rb
tins-0.8.2 lib/tins/deep_const_get.rb
tins-0.8.0 lib/tins/deep_const_get.rb
tins-0.7.4 lib/tins/deep_const_get.rb