module RSence::Plugins

Namespace for plugin classes and modules

Public Class Methods

GUIPlugin() click to toggle source

Creates the runtime GUIPlugin class from GUIPlugin__ @return [GUIPlugin__]

# File lib/rsence/plugins.rb, line 53
def self.GUIPlugin
  lambda do |ns|
    klass = Class.new( GUIPlugin__ ) do
      def self.ns=(ns)
        define_method( :bundle_info ) do
          ns.bundle_info
        end
      end
    end
    klass.ns = ns if ns
    klass
  end
end
Plugin() click to toggle source

Creates the runtime Plugin class from Plugin__ @return [Plugin__]

# File lib/rsence/plugins.rb, line 36
def self.Plugin
  lambda do |ns|
    klass = Class.new( Plugin__ ) do
      def self.ns=(ns)
        define_method( :bundle_info ) do
          ns.bundle_info
        end
      end
    end
    klass.ns = ns if ns
    klass
  end
end
Servlet() click to toggle source

Creates the runtime Servlet class from Servlet__ @return [Servlet__]

# File lib/rsence/plugins.rb, line 70
def self.Servlet
  lambda do |ns|
    klass = Class.new( Servlet__ ) do
      def self.ns=(ns)
        define_method( :bundle_info ) do
          ns.bundle_info
        end
      end
    end
    klass.ns = ns if ns
    klass
  end
end
bundle_loader( params ) click to toggle source

Loads bundle in an anonymous module with special environment options. @param [Hash] params @option params [String] :src_path (‘/path/of/the_plugin/the_plugin.rb’) The ruby source file to read. @option params [String] :bundle_path (‘/path/of/the_plugin’) The plugin bundle directory path. @option params [String] :bundle_name (:the_plugin) The name of the plugin as it will be registered. @return [Module] Isolated, anonymous module containing the evaluated source code of src_path

# File lib/rsence/plugins.rb, line 90
    def self.bundle_loader( params )
      begin
        mod = Module.new do |m|
          if RUBY_VERSION.to_f >= 1.9
            m.define_singleton_method( :_bundle_path ) do
              params[ :bundle_path ]
            end
          else
            m.module_eval( <<-END
            def self._bundle_path; #{params[:bundle_path].inspect}; end
            END
            )
          end
          
          # Makes a full path using the plugin bundle as the 'local path'.
          # The (optional) +prefix+ is a subdirectory in the bundle,
          # the +suffix+ is the file extension.
          def self.bundle_path( path=false, prefix=false, suffix=false )
            return _bundle_path if not path
            if suffix
              path = "#{path}#{suffix}" unless path.end_with?(suffix)
            end
            if prefix
              path = File.join( prefix, path )
            end
            path = File.expand_path( path, _bundle_path )
            return path
          end
          def self.inspect; "#<module BundleWrapper of #{self._bundle_path}}>"; end
          def self.const_missing( name )
            if name == :Servlet
              return Plugins.Servlet.call( self )
            elsif name == :Plugin
              return Plugins.Plugin.call( self )
            elsif name == :GUIPlugin
              return Plugins.GUIPlugin.call( self )
            else
              warn "Known const missing: #{name.inspect}"
              super
            end
          end
          begin
            plugin_src = params[:src]
            unless RUBY_VERSION.to_f >= 1.9
              plugin_src = "_bundle_path = #{params[:bundle_path].inspect};" + plugin_src
            end
            m.module_eval( plugin_src )
          rescue SyntaxError => e
            src_path = params[:src_path]
            src_path = "<undefined src_path>" if src_path == nil
            params[:plugin_manager].plugin_error(
              e,
              'BundleLoaderSyntaxError',
              "The syntax of #{params[:bundle_name]} is invalid.",
              src_path
            )
          rescue => e
            src_path = params[:src_path]
            src_path = "<undefined src_path>" if src_path == nil
            params[:plugin_manager].plugin_error(
              e,
              'BundleLoaderEvalError',
              "An error occurred while evaluating the plugin bundle #{params[:bundle_name]}.",
              src_path
            )
          end
        end
        return mod
      rescue => e
        src_path = params[:src_path]
        src_path = "<undefined src_path>" if src_path == nil
        params[:plugin_manager].plugin_error(
          e,
          'BundleLoaderError',
          "An error occurred while loading the plugin bundle #{params[:bundle_name]}.",
          src_path
        )
      end
    end
bundle_path( path=false, prefix=false, suffix=false ) click to toggle source

Makes a full path using the plugin bundle as the ‘local path’. The (optional) prefix is a subdirectory in the bundle, the suffix is the file extension.

# File lib/rsence/plugins.rb, line 107
def self.bundle_path( path=false, prefix=false, suffix=false )
  return _bundle_path if not path
  if suffix
    path = "#{path}#{suffix}" unless path.end_with?(suffix)
  end
  if prefix
    path = File.join( prefix, path )
  end
  path = File.expand_path( path, _bundle_path )
  return path
end
const_missing( name ) click to toggle source
Calls superclass method
# File lib/rsence/plugins.rb, line 119
def self.const_missing( name )
  if name == :Servlet
    return Plugins.Servlet.call( self )
  elsif name == :Plugin
    return Plugins.Plugin.call( self )
  elsif name == :GUIPlugin
    return Plugins.GUIPlugin.call( self )
  else
    warn "Known const missing: #{name.inspect}"
    super
  end
end
inspect() click to toggle source
# File lib/rsence/plugins.rb, line 118
def self.inspect; "#<module BundleWrapper of #{self._bundle_path}}>"; end
ns=(ns) click to toggle source
# File lib/rsence/plugins.rb, line 39
def self.ns=(ns)
  define_method( :bundle_info ) do
    ns.bundle_info
  end
end