Class: CouchShell::PluginVariablesObject

Inherits:
BasicObject
Defined in:
lib/couch-shell/plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(plugin) ⇒ PluginVariablesObject

Returns a new instance of PluginVariablesObject.



179
180
181
# File 'lib/couch-shell/plugin.rb', line 179

def initialize(plugin)
  @plugin = plugin
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *args) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/couch-shell/plugin.rb', line 183

def method_missing(msg, *args)
  unless args.empty?
    ::Kernel.raise ShellUserError,
      "expected plugin variable lookup: #{msg}"
  end
  varname = msg.to_s
  @plugin.plugin_info.variables.each { |vi|
    begin
      if vi.name && vi.name == varname
        return @plugin.send vi.lookup_message
      end
      if vi.prefix && varname.start_with?(vi.prefix) &&
          varname.length > vi.prefix.length
        return @plugin.send vi.lookup_message, varname[vi.prefix.length]
      end
    rescue Plugin::VarNotSet => e
      e.var = vi
      ::Kernel.raise e
    end
  }
  ::Kernel.raise ShellUserError,
    "no variable #{varname} in plugin #{@plugin.plugin_name}"
end