Module: RSence::Plugins

Defined in:
lib/rsence/plugins.rb,
lib/rsence/plugins.rb,
lib/rsence/plugins/plugin.rb,
lib/rsence/plugins/servlet.rb,
lib/rsence/plugins/guiparser.rb,
lib/rsence/plugins/gui_plugin.rb,
lib/rsence/plugins/plugin_base.rb,
lib/rsence/plugins/plugin_plugins.rb,
lib/rsence/plugins/plugin_sqlite_db.rb

Overview

Namespace for plugin classes and modules

Defined Under Namespace

Modules: PluginBase, PluginPlugins, PluginSqliteDB Classes: GUIParser, GUIPlugin__, Plugin__, Servlet__

Class Method Summary collapse

Class Method Details

.bundle_loader(params) ⇒ Module

Loads bundle in an anonymous module with special environment options.

Parameters:

  • params (Hash)

Options Hash (params):

  • :src_path (String) — default: '/path/of/the_plugin/the_plugin.rb'

    The ruby source file to read.

  • :bundle_path (String) — default: '/path/of/the_plugin'

    The plugin bundle directory path.

  • :bundle_name (String) — default: :the_plugin

    The name of the plugin as it will be registered.

Returns:

  • (Module)

    Isolated, anonymous module containing the evaluated source code of src_path



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rsence/plugins.rb', line 98

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

.GUIPluginGUIPlugin__

Creates the runtime GUIPlugin class from GUIPlugin__

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rsence/plugins.rb', line 61

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

.PluginPlugin__

Creates the runtime Plugin class from Plugin__

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rsence/plugins.rb', line 44

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

.ServletServlet__

Creates the runtime Servlet class from Servlet__

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rsence/plugins.rb', line 78

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