Module: RubyFeatures::Lazy

Defined in:
lib/ruby-features/lazy.rb

Constant Summary collapse

ACTIVE_SUPPORT_LAZY_TARGETS =
%w(
  action_view action_controller action_mailer
  active_record active_job
  i18n
).map(&:to_sym).freeze

Class Method Summary collapse

Class Method Details

.apply(target, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby-features/lazy.rb', line 11

def apply(target, &block)
  if RubyFeatures.active_support_available?
    target_namespace = RubyFeatures::Utils.underscore(target.split('::').first).to_sym

    if ACTIVE_SUPPORT_LAZY_TARGETS.include?(target_namespace)
      return ActiveSupport.on_load target_namespace, yield: true, &block
    end
  end

  yield
end