Module: RubyFeatures::Utils

Defined in:
lib/ruby-features/utils.rb,
lib/ruby-features/utils/inflector.rb,
lib/ruby-features/utils/const_accessor_19.rb,
lib/ruby-features/utils/const_accessor_20.rb,
lib/ruby-features/utils/inflector_active_support.rb

Defined Under Namespace

Modules: ConstAccessor19, ConstAccessor20, Inflector, InflectorActiveSupport

Class Method Summary collapse

Class Method Details

.module_defined?(target, module_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby-features/utils.rb', line 23

def module_defined?(target, module_name)
  ruby_const_defined?(target, module_name) && ruby_const_get(target, module_name).name.start_with?(target.name)
end

.prepare_module(target, module_name) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ruby-features/utils.rb', line 33

def prepare_module(target, module_name)
  inject_const_parts_with_target(target, module_name) do |parent, submodule|
    module_defined?(parent, submodule) ?
      parent.const_get(submodule) :
      parent.const_set(submodule, Module.new)
  end
end

.prepare_module!(target, module_name) ⇒ Object



27
28
29
30
31
# File 'lib/ruby-features/utils.rb', line 27

def prepare_module!(target, module_name)
  module_defined?(target, module_name) ?
    raise(NameError.new("Module already initiated: #{target.name}::#{module_name}")) :
    prepare_module(target, module_name)
end