Sha256: 05149e907bc80a14f838d61ef5953af12cc402bec200b5d84eea91078fa47cad

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'fast_gettext'
require 'gettext_i18n_rails'
require 'fog/xenserver'

module ForemanXen
  # Inherit from the Rails module of the parent app (Foreman), not the plugin.
  # Thus, inherits from ::Rails::Engine and not from Rails::Engine
  class Engine < ::Rails::Engine
    initializer 'foreman_xen.register_gettext', :after => :load_config_initializers do |app|
      locale_dir    = File.join(File.expand_path('../../..', __FILE__), 'locale')
      locale_domain = 'foreman-xen'

      Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
    end

    initializer 'foreman_xen.register_plugin', :before => :finisher_hook do |app|
      Foreman::Plugin.register :foreman_xen do
        requires_foreman '>= 1.13'
        # Register xen compute resource in foreman
        compute_resource ForemanXen::Xenserver
        parameter_filter(ComputeResource, :uuid)
      end
    end

    assets_to_precompile =
      Dir.chdir(root) do
        Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
          f.split(File::SEPARATOR, 4).last
        end
      end

    initializer 'foreman_xen.assets.precompile' do |app|
      app.config.assets.precompile += assets_to_precompile
    end

    initializer 'foreman_xen.configure_assets', group: :assets do
      SETTINGS[:foreman_xen] = { assets: { precompile: assets_to_precompile } }
    end

    config.to_prepare do
      begin
        # extend fog xen server and image models.
        require 'fog/compute/xen_server/models/server'
        require File.expand_path('../../../app/models/concerns/fog_extensions/xenserver/server', __FILE__)
        require File.expand_path('../../../app/models/concerns/foreman_xen/host_helper_extensions', __FILE__)

        Fog::Compute::XenServer::Server.send(:include, ::FogExtensions::Xenserver::Server)
        ::HostsHelper.send(:include, ForemanXen::HostHelperExtensions)
      rescue => e
        Rails.logger.warn "Foreman-Xen: skipping engine hook (#{e})"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_xen-0.5.0 lib/foreman_xen/engine.rb