File: railtie.rb

package info (click to toggle)
ruby-recaptcha 5.21.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: ruby: 662; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 820 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Recaptcha
  class Railtie < Rails::Railtie
    ActiveSupport.on_load(:action_view) do
      include Recaptcha::Adapters::ViewMethods
    end

    ActiveSupport.on_load(:action_controller) do
      include Recaptcha::Adapters::ControllerMethods
    end

    initializer 'recaptcha' do |app|
      Recaptcha::Railtie.instance_eval do
        pattern = pattern_from app.config.i18n.available_locales

        add("rails/locales/#{pattern}.yml")
      end
    end

    class << self
      protected

      def add(pattern)
        files = Dir[File.join(File.dirname(__FILE__), '../..', pattern)]
        I18n.load_path.concat(files)
      end

      def pattern_from(args)
        array = Array(args || [])
        array.blank? ? '*' : "{#{array.join ','}}"
      end
    end
  end
end