Sha256: f35fd13286e68db48a2a5c1c2b2e823bfc948be6383e9fae5bfe0330a458d73d

Contents?: true

Size: 1.67 KB

Versions: 16

Compression:

Stored size: 1.67 KB

Contents

module I18n
  module JS
    # When using `safe_gem_check` to check for a pre-release version of gem,
    # we need to specify pre-release version suffix in version constraint
    module Dependencies
      class << self
        def rails?
          defined?(Rails) && Rails.respond_to?(:version)
        end

        def sprockets_rails_v2_plus?
          safe_gem_check("sprockets-rails", ">= 2")
        end

        # This cannot be called at class definition time
        # Since not all libraries are loaded
        #
        # Call this in an initializer
        def using_asset_pipeline?
          assets_pipeline_available =
            (rails3? || rails4? || rails5? || rails6?) &&
            Rails.respond_to?(:application) &&
            Rails.application.config.respond_to?(:assets)
          rails3_assets_enabled =
            rails3? &&
            assets_pipeline_available &&
            Rails.application.config.assets.enabled != false

          assets_pipeline_available && (rails4? || rails5? || rails6? || rails3_assets_enabled)
        end

        private

        def rails3?
          rails? && Rails.version.to_i == 3
        end

        def rails4?
          rails? && Rails.version.to_i == 4
        end

        def rails5?
          rails? && Rails.version.to_i == 5
        end

        def rails6?
          rails? && Rails.version.to_i == 6
        end

        def safe_gem_check(*args)
          if Gem::Specification.respond_to?(:find_by_name)
            Gem::Specification.find_by_name(*args)
          elsif Gem.respond_to?(:available?)
            Gem.available?(*args)
          end
        rescue Gem::LoadError
          false
        end

      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
i18n-js-3.9.0 lib/i18n/js/dependencies.rb
i18n-js-3.8.4 lib/i18n/js/dependencies.rb
i18n-js-3.8.3 lib/i18n/js/dependencies.rb
i18n-js-3.8.2 lib/i18n/js/dependencies.rb
i18n-js-3.8.1 lib/i18n/js/dependencies.rb
i18n-js-3.8.0 lib/i18n/js/dependencies.rb
i18n-js-3.7.1 lib/i18n/js/dependencies.rb
i18n-js-3.7.0 lib/i18n/js/dependencies.rb
i18n-js-3.6.0 lib/i18n/js/dependencies.rb
i18n-js-3.5.1 lib/i18n/js/dependencies.rb
i18n-js-3.5.0 lib/i18n/js/dependencies.rb
i18n-js-3.4.2 lib/i18n/js/dependencies.rb
i18n-js-3.4.1 lib/i18n/js/dependencies.rb
i18n-js-3.4.0 lib/i18n/js/dependencies.rb
i18n-js-3.3.0 lib/i18n/js/dependencies.rb
i18n-js-3.2.3 lib/i18n/js/dependencies.rb