Sha256: 4054399110338a334293ff5f93d65308465fef9f001d545721dffcd7ea4b562c

Contents?: true

Size: 653 Bytes

Versions: 9

Compression:

Stored size: 653 Bytes

Contents

# frozen_string_literal: true

module ActionPolicy
  module Ext
    # Add Module#namespace method
    module ModuleNamespace # :nodoc: all
      unless "".respond_to?(:safe_constantize)
        require "action_policy/ext/string_constantize"
        using ActionPolicy::Ext::StringConstantize
      end

      module Ext
        def namespace
          return unless name&.match?(/[^^]::/)

          name.sub(/::[^:]+$/, "").safe_constantize
        end
      end

      # See https://github.com/jruby/jruby/issues/5220
      ::Module.include(Ext) if RUBY_PLATFORM.match?(/java/i)

      refine Module do
        include Ext
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
action_policy-0.6.0 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.7 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.6 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.5 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.4 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.3 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.2 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.1 lib/action_policy/ext/module_namespace.rb
action_policy-0.5.0 lib/action_policy/ext/module_namespace.rb