Sha256: 126944404b61f4255becf2601738cf3a629494af74e04b2dd7ca4aaf9ca8262d

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require_relative 'coverage/launch'

module Bizside
  class Railtie < ::Rails::Railtie

    # ロケールファイル
    initializer 'bizside-i18n' do |app|
      Bizside::Railtie.instance_eval do
        pattern = pattern_from(app.config.i18n.available_locales)
        add("rails/locales/#{pattern}.yml")
      end
    end

    # ビューのヘルパーメソッド
    initializer 'view_helper' do
      require_relative 'view_helper'

      ActiveSupport.on_load(:action_view) do
        include Bizside::ViewHelper
      end
    end

    # 警告バリデーション
    if Bizside.config.warning_validation.enabled?
      require_relative 'warning'

      initializer 'warning_validation' do
        ActiveSupport.on_load :active_record do
          include Bizside::Warning
        end
      end
    end

    if Bizside.config.user_agent.enabled?
      require_relative 'user_agent'

      initializer 'user_agent' do
        require_relative 'user_agent/action_view'

        ActiveSupport.on_load(:action_controller) do
          include Bizside::UserAgent::ControllerHelper
        end
      end
    end

    if Bizside.config.acl.enabled?
      require_relative 'acl'

      initializer 'acl' do
        ActiveSupport.on_load(:action_controller) do
          include Bizside::Acl::ControllerHelper
        end
        ActiveSupport.on_load(:action_view) do
          include Bizside::Acl::AvailableHelper
        end
      end
    end

    unless Bizside.config.active_record_logger.enabled?
      initializer 'active_record_logger' do
        ActiveSupport.on_load(:active_record) do
          require_relative 'active_record_logger'
        end
      end
    end

    protected

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

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bizside-2.0.2 lib/bizside/railtie.rb
bizside-2.0.1 lib/bizside/railtie.rb