Sha256: 0078259e92bb86af3f3efd84948def94a67f773a2ada03993fa563bc26126494

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

module Locomotive
  module Plugin
    # This module provides initialization methods to the plugin class which Locomotive CMS will call after the plugin has been loaded into the app.
    module LoadInitialization

      # @private
      #
      # Add class methods.
      #
      # @param base the class which includes this module
      def self.included(base)
        base.extend(ClassMethods)
      end

      # @api internal
      module ClassMethods
        # Adds methods from LoadInitializationClassMethods module.
        #
        # @param base the plugin class to extend LoadInitializationClassMethods
        def add_load_initialization_class_methods(base)
          base.extend(LoadInitializationClassMethods)
        end
      end

      # This module adds class-level initialization methods to the plugin class.
      module LoadInitializationClassMethods
        # Performs class-level initialization and ensures that it is only done
        # once. If a block is given, that block is called before the custom
        # `plugin_loaded` method is called. LocomotiveCMS calls this method on
        # all plugins after they are loaded.
        def do_load_initialization
          raise InitializationError,
            'cannot initialize plugin more than once!' if @done_load_inialization

          @done_load_inialization = true

          yield if block_given?

          self.plugin_loaded
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotive_plugins-1.2.0 lib/locomotive/plugin/load_initialization.rb
locomotive_plugins-1.1.1 lib/locomotive/plugin/load_initialization.rb
locomotive_plugins-1.1.0 lib/locomotive/plugin/load_initialization.rb
locomotive_plugins-1.0.1 lib/locomotive/plugin/load_initialization.rb
locomotive_plugins-1.0.0.beta10 lib/locomotive/plugin/load_initialization.rb