An abstract base class for Arrow applets. Provides execution logic, argument-parsing/untainting/validation, and templating through an injected factory.
Set the appicon for the applet to imgfile.
# File lib/arrow/applet.rb, line 264
264: def self::appicon( imgfile )
265: self.signature.appicon = imgfile
266: end
Set the description of the applet to desc.
# File lib/arrow/applet.rb, line 233
233: def self::applet_description( desc )
234: self.signature.description = desc
235: end
Set the contact information for the maintainer of the applet to info.
# File lib/arrow/applet.rb, line 239
239: def self::applet_maintainer( info )
240: self.signature.maintainer = info
241: end
Set the name of the applet to name.
# File lib/arrow/applet.rb, line 227
227: def self::applet_name( name )
228: self.signature.name = name
229: end
Set the contact information for the maintainer of the applet to info.
# File lib/arrow/applet.rb, line 245
245: def self::applet_version( ver )
246: self.signature.version = ver
247: end
Define an action for the applet. Transactions which include the specified name as the first directory of the uri after the one the applet is assigned to will be passed to the given block. The return value from this method is an Arrow::Applet::SigProxy which can be used to set associated values in the applet‘s Signature; see the Synopsis in lib/arrow/applet.rb for examples of how to use this.
# File lib/arrow/applet.rb, line 405
405: def self::def_action( name, &block )
406: name = '_default' if name.to_s.empty?
407:
408: # Action must accept at least a transaction argument
409: unless block.arity.nonzero?
410: raise ScriptError,
411: "Malformed action #{name}: must accept at least one argument"
412: end
413:
414: methodName = "#{name}_action"
415: define_method( methodName, &block )
416: SigProxy.new( name, self )
417: end
Set the default action for the applet to action.
# File lib/arrow/applet.rb, line 251
251: def self::default_action( action )
252: self.signature.default_action = action.to_s
253: end
Inheritance callback: register any derivative classes so they can be looked up later.
# File lib/arrow/applet.rb, line 271
271: def self::inherited( klass )
272: @inherited_from = true
273: if defined?( @newly_loaded )
274: @newly_loaded.push( klass )
275: super
276: else
277: Arrow::Applet.inherited( klass )
278: end
279: end
Have any subclasses of this class been created?
# File lib/arrow/applet.rb, line 283
283: def self::inherited_from?
284: @inherited_from
285: end
Load any applet classes in the given file and return them. Ignores any class which has a subclass in the file unless include_base_classes is set false
# File lib/arrow/applet.rb, line 301
301: def self::load( filename, include_base_classes=false )
302: self.newly_loaded.clear
303:
304: # Load the applet file in an anonymous module. Any applet classes get
305: # collected via the ::inherited hook into @newly_loaded
306: Kernel.load( filename, true )
307:
308: newderivatives = @newly_loaded.dup
309: @derivatives -= @newly_loaded
310: @derivatives.push( *@newly_loaded )
311:
312: newderivatives.each do |applet|
313: applet.filename = filename
314: end
315:
316: unless include_base_classes
317: newderivatives.delete_if do |applet|
318: applet.inherited_from?
319: end
320: end
321:
322: return newderivatives
323: end
Signature lookup: look for either a constant or an instance variable of the class that contains the raw signature hash, and convert it to an Arrow::Applet::SignatureStruct object.
# File lib/arrow/applet.rb, line 349
349: def self::make_signature
350: rawsig = nil
351: if self.instance_variables.include?( "@signature" )
352: rawsig = self.instance_variable_get( :@signature )
353: elsif self.constants.include?( "Signature" )
354: rawsig = self.const_get( :Signature )
355: elsif self.constants.include?( "SIGNATURE" )
356: rawsig = self.const_get( :SIGNATURE )
357: else
358: rawsig = {}
359: end
360:
361: # Backward-compatibility: Rewrite the 'vargs' member as
362: # 'validator_profiles' if 'vargs' exists and 'validator_profiles'
363: # doesn't. 'vargs' member will be deleted regardless.
364: rawsig[ :validator_profiles ] ||= rawsig.delete( :vargs ) if
365: rawsig.key?( :vargs )
366:
367: # If the superclass has a signature, inherit values from it for
368: # pairs that are missing.
369: if self.superclass < Arrow::Applet && self.superclass.signature?
370: self.superclass.signature.each_pair do |member,value|
371: next if [:name, :description, :version].include?( member )
372: if rawsig[member].nil?
373: rawsig[ member ] = value.dup rescue value
374: end
375: end
376: end
377:
378: # Apply sensible defaults for members that aren't defined
379: SignatureStructDefaults.each do |key,val|
380: next if rawsig[ key ]
381: case val
382: when Proc, Method
383: rawsig[ key ] = val.call( rawsig, self )
384: when Numeric, NilClass, FalseClass, TrueClass
385: rawsig[ key ] = val
386: else
387: rawsig[ key ] = val.dup
388: end
389: end
390:
391: # Signature = Struct.new( :name, :description, :maintainer,
392: # :version, :config, :default_action, :templates, :validatorArgs,
393: # :monitors )
394: members = SignatureStruct.members.collect {|m| m.intern}
395: return SignatureStruct.new( *rawsig.values_at(*members) )
396: end
Method definition callback: Check newly-defined action methods for appropriate arity.
# File lib/arrow/applet.rb, line 290
290: def self::method_added( sym )
291: if /^(\w+)_action$/.match( sym.to_s ) &&
292: self.instance_method( sym ).arity.zero?
293: raise ScriptError, "Inappropriate arity for #{sym}", caller(1)
294: end
295: end
Create a new Arrow::Applet object with the specified config (an Arrow::Config object), template_factory (an Arrow::TemplateFactory object), and the uri the applet will live under in the appserver (a String).
# File lib/arrow/applet.rb, line 432
432: def initialize( config, template_factory, uri )
433: @config = config
434: @template_factory = template_factory
435: @uri = uri
436:
437: @signature = self.class.signature.dup
438: @run_count = 0
439: @total_utime = 0
440: @total_stime = 0
441:
442: # Make a regexp out of all public <something>_action methods
443: @actions = self.public_methods( true ).
444: select {|meth| /^(\w+)_action$/ =~ meth }.
445: collect {|meth| meth.gsub(/_action/, '') }
446: @actions_regexp = Regexp.new( "^(" + actions.join( '|' ) + ")$" )
447: end
Return the name of the applet class after stripping off any namespace-safe prefixes.
# File lib/arrow/applet.rb, line 328
328: def self::normalized_name
329: self.name.sub( /#<Module:0x\w+>::/, '' )
330: end
Get the applet‘s signature (an Arrow::Applet::SignatureStruct object).
# File lib/arrow/applet.rb, line 335
335: def self::signature
336: @signature ||= make_signature()
337: end
Returns true if the applet class has a signature.
# File lib/arrow/applet.rb, line 341
341: def self::signature?
342: !self.signature.nil?
343: end
Set the path for the template specified by sym to path.
# File lib/arrow/applet.rb, line 212
212: def self::template( sym, path=nil )
213: case sym
214: when Symbol, String
215: self.signature.templates[ sym ] = path
216:
217: when Hash
218: self.signature.templates.merge!( sym )
219:
220: else
221: raise ArgumentError, "cannot convert %s to Symbol" % [ sym ]
222: end
223: end
Set the validator rules for the specified action.
# File lib/arrow/applet.rb, line 258
258: def self::validator( action, rules={} )
259: self.signature.validator_profiles[ action ] = rules
260: end
The action invoked if the specified action is not explicitly defined. The default implementation will look for a template with the same key as the action, and if found, will load that and return it.
# File lib/arrow/applet.rb, line 570
570: def action_missing_action( txn, raction, *args )
571: self.log.debug "In action_missing_action with: raction = %p, args = %p" %
572: [ raction, args ]
573:
574: if raction && @signature.templates.key?( raction.to_s.intern )
575: self.log.debug "Using template sender default action for %s" % raction
576: txn.vargs = self.make_validator( raction, txn )
577: tmpl = self.load_template( raction.intern )
578: tmpl.txn = txn
579: return tmpl
580: else
581: raise Arrow::AppletError, "No such action '%s' in %s" %
582: [ raction, self.signature.name ]
583: end
584: end
Returns the average number of seconds (user + system) per run.
# File lib/arrow/applet.rb, line 600
600: def average_usage
601: return 0.0 if @run_count.zero?
602: (@total_utime + @total_stime) / @run_count.to_f
603: end
Returns true if the receiver has a #delegate method that is inherited from somewhere other than the base Arrow::Applet class.
# File lib/arrow/applet.rb, line 561
561: def delegable?
562: return self.method(:delegate).to_s !~ /\(Arrow::Applet\)/
563: end
Wrapper method for a delegation (chained) request.
# File lib/arrow/applet.rb, line 554
554: def delegate( txn, chain, *args )
555: yield( chain )
556: end
Return a human-readable String representing the applet.
# File lib/arrow/applet.rb, line 588
588: def inspect
589: "<%s:0x%08x: %s [%s/%s]>" % [
590: self.class.name,
591: self.object_id * 2,
592: @signature.name,
593: @signature.version,
594: @signature.maintainer
595: ]
596: end
Given an action name (or nil for the default action), return a Method for the action method which should be invoked on the specified txn.
# File lib/arrow/applet.rb, line 533
533: def lookup_action_method( txn, action, *args )
534: self.log.debug "Mapping %s( %p ) to an action" % [ action, args ]
535:
536: # Look up the Method object that needs to be called
537: if (( match = @actions_regexp.match(action.to_s) ))
538: action = match.captures[0]
539: action.untaint
540: self.log.debug "Matched action = #{action}"
541: else
542: self.log.info "Couldn't find specified action %p. "\
543: "Defaulting to the 'action_missing' action." % action
544: args.unshift( action )
545: action = "action_missing"
546: end
547:
548: return self.method( "#{action}_action" ), *args
549: end
Run the specified action for the given txn and the specified args.
# File lib/arrow/applet.rb, line 481
481: def run( txn, action=nil, *args )
482: starttimes = Process.times
483: self.log.debug "Running %s" % [ self.signature.name ]
484:
485: action = nil if action.to_s.empty?
486: action ||= @signature.default_action or
487: raise Arrow::AppletError, "Missing default handler '#{default}'"
488:
489: # Do any initial preparation of the transaction that can be factored out
490: # of all the actions.
491: self.prep_transaction( txn )
492: meth, *args = self.lookup_action_method( txn, action, *args )
493: self.log.debug "Action method is: %p" % [meth]
494: txn.vargs = self.make_validator( action, txn )
495:
496: # Now either pass control to the block, if given, or invoke the
497: # action
498: if block_given?
499: self.log.debug "Yielding to passed block"
500: rval = yield( meth, txn, *args )
501: else
502: self.log.debug "Applet action arity: %d; args = %p" %
503: [ meth.arity, args ]
504:
505: # Invoke the action with the right number of arguments.
506: if meth.arity < 0
507: rval = meth.call( txn, *args )
508: elsif meth.arity >= 1
509: args.unshift( txn )
510: until args.length >= meth.arity do args << nil end
511: rval = meth.call( *(args[0, meth.arity]) )
512: else
513: raise Arrow::AppletError,
514: "Malformed action: Must accept at least a transaction argument"
515: end
516: end
517:
518: # Calculate CPU times
519: runtimes = Process.times
520: @run_count += 1
521: @total_utime += utime = (runtimes.utime - starttimes.utime)
522: @total_stime += stime = (runtimes.stime - starttimes.stime)
523: self.log.info \
524: "[PID %d] Runcount: %d, User: %0.2f/%0.2f, System: %0.2f/%0.2f" %
525: [ Process.pid, @run_count, utime, @total_utime, stime, @total_stime ]
526:
527: return rval
528: end
Return the validator profile that corresponds to the action which will be executed by the specified txn. Returns the default profile if no more-specific one is available.
# File lib/arrow/applet.rb, line 657
657: def get_validator_profile_for_action( action, txn )
658: if action.to_s =~ /^(\w+)$/
659: action = $1
660: action.untaint
661: else
662: self.log.warning "Invalid action '#{action.inspect}'"
663: action = :__default__
664: end
665:
666: # Look up the profile for the applet or the default one
667: profile = @signature.validator_profiles[ action.to_sym ] ||
668: @signature.validator_profiles[ :__default__ ]
669:
670: if profile.nil?
671: self.log.warning "No validator for #{action}, and no __default__. "\
672: "Returning nil validator."
673: return nil
674: end
675:
676: return profile
677: end
Load and return the template associated with the given key according to the applet‘s signature. Returns nil if no such template exists.
# File lib/arrow/applet.rb, line 640
640: def load_template( key )
641:
642: tname = @signature.templates[key] or
643: raise Arrow::AppletError,
644: "No such template %p defined in the signature for %s (%s)" %
645: [ key, self.signature.name, self.class.filename ]
646:
647: tname.untaint
648:
649: return @template_factory.get_template( tname )
650: end
Create a FormValidator object for the specified action which has been given the arguments from the given txn.
# File lib/arrow/applet.rb, line 682
682: def make_validator( action, txn )
683: profile = self.get_validator_profile_for_action( action, txn ) or
684: return nil
685:
686: # Create a new validator object, map the request args into a regular
687: # hash, and then send them to the validaator with the applicable profile
688: self.log.debug "Creating form validator for profile: %p" % profile
689:
690: params = {}
691:
692: # Only try to parse form parameters if there's a form
693: if txn.form_request?
694: txn.request.paramtable.each do |key,val|
695: # Multi-valued vs. single params
696: params[key] = val.to_a.length > 1 ? val.to_a : val.to_s
697: end
698: end
699: validator = Arrow::FormValidator.new( profile, params )
700:
701: self.log.debug "Validator: %p" % validator
702: return validator
703: end
Prepares the transaction (txn) for applet execution. By default, this method sets the content type of the response to ‘text/html’ and turns off buffering for the header.
# File lib/arrow/applet.rb, line 632
632: def prep_transaction( txn )
633: txn.request.content_type = "text/html"
634: txn.request.sync_header = true
635: end
Run an action with a duped transaction (e.g., from another action)
# File lib/arrow/applet.rb, line 611
611: def subrun( action, txn, *args )
612: action, txn = txn, action if action.is_a?( Arrow::Transaction )
613: self.log.debug "Running subordinate action '%s' from '%s'" %
614: [ action, caller[0] ]
615:
616: # Make sure the transaction has stuff loaded. This is necessary when
617: # #subrun is called without going through #run first (e.g., via
618: # #delegate)
619: if txn.vargs.nil?
620: self.prep_transaction( txn )
621: txn.vargs = self.make_validator( action, txn )
622: end
623:
624: meth, *args = self.lookup_action_method( txn, action, *args )
625: return meth.call( txn, *args )
626: end
--- SEC00016
--- ""
--- | Class <a href="Applet/SigProxy.html" class="link">Arrow::Applet::SigProxy</a><br />
---
- name: actions
rw: R
a_desc: |+
The list of all valid actions on the applet
- name: config
rw: RW
a_desc: |+
The <a href="Config.html">Arrow::Config</a> object which contains the
system‘s configuration.
- name: derivatives
rw: R
a_desc: |+
The Array of loaded applet classes (derivatives)
- name: filename
rw: RW
a_desc: |+
The file containing the applet‘s class definition
- name: newly_loaded
rw: R
a_desc: |+
The Array of applet classes that were loaded by the most recent call to .<a
href="Applet.html#M000557">load</a>.
- name: run_count
rw: R
a_desc: |+
The number of times this particular applet object has been <a
href="Applet.html#M000564">run</a>
- name: signature
rw: R
a_desc: |+
The Struct that contains the configuration values for this applet
- name: template_factory
rw: R
a_desc: |+
The <a href="TemplateFactory.html">Arrow::TemplateFactory</a> object used
to <a href="Applet.html#M000557">load</a> templates for the applet.
- name: total_stime
rw: R
a_desc: |+
The number of system seconds spent in this applet‘s <a
href="Applet.html#M000564">#run</a> method.
- name: total_utime
rw: R
a_desc: |+
The number of user seconds spent in this applet‘s <a
href="Applet.html#M000564">#run</a> method.
- name: uri
rw: R
a_desc: |+
The URI the applet answers to
---
- methods:
- visibility: public
aref: M000553
name: appicon
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 264</span>\n\
264: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">appicon</span>( <span class=\"ruby-identifier\">imgfile</span> )\n\
265: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">appicon</span> = <span class=\"ruby-identifier\">imgfile</span>\n\
266: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the <a href="Applet.html#M000553">appicon</a> for the applet to
<tt>imgfile</tt>.
</p>
params: ( imgfile )
- visibility: public
aref: M000548
name: applet_description
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 233</span>\n\
233: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">applet_description</span>( <span class=\"ruby-identifier\">desc</span> )\n\
234: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">description</span> = <span class=\"ruby-identifier\">desc</span> \n\
235: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the description of the applet to <tt>desc</tt>.
</p>
params: ( desc )
- visibility: public
aref: M000549
name: applet_maintainer
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 239</span>\n\
239: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">applet_maintainer</span>( <span class=\"ruby-identifier\">info</span> )\n\
240: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">maintainer</span> = <span class=\"ruby-identifier\">info</span>\n\
241: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the contact information for the maintainer of the applet to
<tt>info</tt>.
</p>
params: ( info )
- visibility: public
aref: M000547
name: applet_name
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 227</span>\n\
227: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">applet_name</span>( <span class=\"ruby-identifier\">name</span> )\n\
228: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">name</span> = <span class=\"ruby-identifier\">name</span>\n\
229: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the name of the applet to <tt>name</tt>.
</p>
params: ( name )
- visibility: public
aref: M000550
name: applet_version
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 245</span>\n\
245: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">applet_version</span>( <span class=\"ruby-identifier\">ver</span> )\n\
246: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">version</span> = <span class=\"ruby-identifier\">ver</span>\n\
247: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the contact information for the maintainer of the applet to
<tt>info</tt>.
</p>
params: ( ver )
- visibility: public
aref: M000562
name: def_action
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 405</span>\n\
405: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">def_action</span>( <span class=\"ruby-identifier\">name</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
406: <span class=\"ruby-identifier\">name</span> = <span class=\"ruby-value str\">'_default'</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">name</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">empty?</span>\n\
407: \n\
408: <span class=\"ruby-comment cmt\"># Action must accept at least a transaction argument</span>\n\
409: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">block</span>.<span class=\"ruby-identifier\">arity</span>.<span class=\"ruby-identifier\">nonzero?</span>\n\
410: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ScriptError</span>,\n\
411: <span class=\"ruby-node\">"Malformed action #{name}: must accept at least one argument"</span>\n\
412: <span class=\"ruby-keyword kw\">end</span>\n\
413: \n\
414: <span class=\"ruby-identifier\">methodName</span> = <span class=\"ruby-node\">"#{name}_action"</span>\n\
415: <span class=\"ruby-identifier\">define_method</span>( <span class=\"ruby-identifier\">methodName</span>, <span class=\"ruby-operator\">&</span><span class=\"ruby-identifier\">block</span> )\n\
416: <span class=\"ruby-constant\">SigProxy</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-identifier\">name</span>, <span class=\"ruby-keyword kw\">self</span> )\n\
417: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Define an action for the applet. Transactions which include the specified
<tt>name</tt> as the first directory of the uri after the one the applet is
assigned to will be passed to the given <tt>block</tt>. The return value
from this method is an <a
href="Applet/SigProxy.html">Arrow::Applet::SigProxy</a> which can be used
to set associated values in the applet‘s Signature; see the Synopsis
in lib/arrow/applet.rb for examples of how to use this.
</p>
params: ( name, &block )
- visibility: public
aref: M000551
name: default_action
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 251</span>\n\
251: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">default_action</span>( <span class=\"ruby-identifier\">action</span> )\n\
252: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">default_action</span> = <span class=\"ruby-identifier\">action</span>.<span class=\"ruby-identifier\">to_s</span>\n\
253: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Set the default action for the applet to <tt>action</tt>.
</p>
params: ( action )
- visibility: public
aref: M000554
name: inherited
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 271</span>\n\
271: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">inherited</span>( <span class=\"ruby-identifier\">klass</span> )\n\
272: <span class=\"ruby-ivar\">@inherited_from</span> = <span class=\"ruby-keyword kw\">true</span>\n\
273: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">defined?</span>( <span class=\"ruby-ivar\">@newly_loaded</span> )\n\
274: <span class=\"ruby-ivar\">@newly_loaded</span>.<span class=\"ruby-identifier\">push</span>( <span class=\"ruby-identifier\">klass</span> )\n\
275: <span class=\"ruby-keyword kw\">super</span>\n\
276: <span class=\"ruby-keyword kw\">else</span>\n\
277: <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Applet</span>.<span class=\"ruby-identifier\">inherited</span>( <span class=\"ruby-identifier\">klass</span> )\n\
278: <span class=\"ruby-keyword kw\">end</span>\n\
279: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Inheritance callback: register any derivative classes so they can be looked
up later.
</p>
params: ( klass )
- visibility: public
aref: M000555
name: inherited_from?
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 283</span>\n\
283: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">inherited_from?</span>\n\
284: <span class=\"ruby-ivar\">@inherited_from</span>\n\
285: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Have any subclasses of this class been created?
</p>
params: ()
- visibility: public
aref: M000557
name: load
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 301</span>\n\
301: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">load</span>( <span class=\"ruby-identifier\">filename</span>, <span class=\"ruby-identifier\">include_base_classes</span>=<span class=\"ruby-keyword kw\">false</span> )\n\
302: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">newly_loaded</span>.<span class=\"ruby-identifier\">clear</span>\n\
303: \n\
304: <span class=\"ruby-comment cmt\"># Load the applet file in an anonymous module. Any applet classes get</span>\n\
305: <span class=\"ruby-comment cmt\"># collected via the ::inherited hook into @newly_loaded</span>\n\
306: <span class=\"ruby-constant\">Kernel</span>.<span class=\"ruby-identifier\">load</span>( <span class=\"ruby-identifier\">filename</span>, <span class=\"ruby-keyword kw\">true</span> )\n\
307: \n\
308: <span class=\"ruby-identifier\">newderivatives</span> = <span class=\"ruby-ivar\">@newly_loaded</span>.<span class=\"ruby-identifier\">dup</span>\n\
309: <span class=\"ruby-ivar\">@derivatives</span> <span class=\"ruby-operator\">-=</span> <span class=\"ruby-ivar\">@newly_loaded</span>\n\
310: <span class=\"ruby-ivar\">@derivatives</span>.<span class=\"ruby-identifier\">push</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-ivar\">@newly_loaded</span> )\n\
311: \n\
312: <span class=\"ruby-identifier\">newderivatives</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">applet</span><span class=\"ruby-operator\">|</span>\n\
313: <span class=\"ruby-identifier\">applet</span>.<span class=\"ruby-identifier\">filename</span> = <span class=\"ruby-identifier\">filename</span>\n\
314: <span class=\"ruby-keyword kw\">end</span>\n\
315: \n\
316: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">include_base_classes</span>\n\
317: <span class=\"ruby-identifier\">newderivatives</span>.<span class=\"ruby-identifier\">delete_if</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">applet</span><span class=\"ruby-operator\">|</span>\n\
318: <span class=\"ruby-identifier\">applet</span>.<span class=\"ruby-identifier\">inherited_from?</span>\n\
319: <span class=\"ruby-keyword kw\">end</span>\n\
320: <span class=\"ruby-keyword kw\">end</span>\n\
321: \n\
322: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">newderivatives</span>\n\
323: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Load any applet classes in the given file and return them. Ignores any
class which has a subclass in the file unless <tt>include_base_classes</tt>
is set false
</p>
params: ( filename, include_base_classes=false )
- visibility: public
aref: M000561
name: make_signature
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 349</span>\n\
349: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">make_signature</span>\n\
350: <span class=\"ruby-identifier\">rawsig</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
351: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">instance_variables</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-value str\">"@signature"</span> )\n\
352: <span class=\"ruby-identifier\">rawsig</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">instance_variable_get</span>( <span class=\"ruby-identifier\">:@signature</span> )\n\
353: <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">constants</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-value str\">"Signature"</span> )\n\
354: <span class=\"ruby-identifier\">rawsig</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">const_get</span>( <span class=\"ruby-identifier\">:Signature</span> )\n\
355: <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">constants</span>.<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-value str\">"SIGNATURE"</span> )\n\
356: <span class=\"ruby-identifier\">rawsig</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">const_get</span>( <span class=\"ruby-identifier\">:SIGNATURE</span> )\n\
357: <span class=\"ruby-keyword kw\">else</span>\n\
358: <span class=\"ruby-identifier\">rawsig</span> = {}\n\
359: <span class=\"ruby-keyword kw\">end</span>\n\
360: \n\
361: <span class=\"ruby-comment cmt\"># Backward-compatibility: Rewrite the 'vargs' member as</span>\n\
362: <span class=\"ruby-comment cmt\"># 'validator_profiles' if 'vargs' exists and 'validator_profiles'</span>\n\
363: <span class=\"ruby-comment cmt\"># doesn't. 'vargs' member will be deleted regardless.</span>\n\
364: <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">:validator_profiles</span> ] <span class=\"ruby-operator\">||=</span> <span class=\"ruby-identifier\">rawsig</span>.<span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">:vargs</span> ) <span class=\"ruby-keyword kw\">if</span>\n\
365: <span class=\"ruby-identifier\">rawsig</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">:vargs</span> )\n\
366: \n\
367: <span class=\"ruby-comment cmt\"># If the superclass has a signature, inherit values from it for</span>\n\
368: <span class=\"ruby-comment cmt\"># pairs that are missing.</span>\n\
369: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">superclass</span> <span class=\"ruby-operator\"><</span> <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Applet</span> <span class=\"ruby-operator\">&&</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">superclass</span>.<span class=\"ruby-identifier\">signature?</span>\n\
370: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">superclass</span>.<span class=\"ruby-identifier\">signature</span>.<span class=\"ruby-identifier\">each_pair</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">member</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span>\n\
371: <span class=\"ruby-keyword kw\">next</span> <span class=\"ruby-keyword kw\">if</span> [<span class=\"ruby-identifier\">:name</span>, <span class=\"ruby-identifier\">:description</span>, <span class=\"ruby-identifier\">:version</span>].<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-identifier\">member</span> )\n\
372: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">rawsig</span>[<span class=\"ruby-identifier\">member</span>].<span class=\"ruby-identifier\">nil?</span>\n\
373: <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">member</span> ] = <span class=\"ruby-identifier\">value</span>.<span class=\"ruby-identifier\">dup</span> <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-identifier\">value</span>\n\
374: <span class=\"ruby-keyword kw\">end</span>\n\
375: <span class=\"ruby-keyword kw\">end</span>\n\
376: <span class=\"ruby-keyword kw\">end</span>\n\
377: \n\
378: <span class=\"ruby-comment cmt\"># Apply sensible defaults for members that aren't defined</span>\n\
379: <span class=\"ruby-constant\">SignatureStructDefaults</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">val</span><span class=\"ruby-operator\">|</span>\n\
380: <span class=\"ruby-keyword kw\">next</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">key</span> ]\n\
381: <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">val</span>\n\
382: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Proc</span>, <span class=\"ruby-constant\">Method</span>\n\
383: <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-identifier\">val</span>.<span class=\"ruby-identifier\">call</span>( <span class=\"ruby-identifier\">rawsig</span>, <span class=\"ruby-keyword kw\">self</span> )\n\
384: <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Numeric</span>, <span class=\"ruby-constant\">NilClass</span>, <span class=\"ruby-constant\">FalseClass</span>, <span class=\"ruby-constant\">TrueClass</span>\n\
385: <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-identifier\">val</span>\n\
386: <span class=\"ruby-keyword kw\">else</span>\n\
387: <span class=\"ruby-identifier\">rawsig</span>[ <span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-identifier\">val</span>.<span class=\"ruby-identifier\">dup</span>\n\
388: <span class=\"ruby-keyword kw\">end</span>\n\
389: <span class=\"ruby-keyword kw\">end</span>\n\
390: \n\
391: <span class=\"ruby-comment cmt\"># Signature = Struct.new( :name, :description, :maintainer,</span>\n\
392: <span class=\"ruby-comment cmt\"># :version, :config, :default_action, :templates, :validatorArgs,</span>\n\
393: <span class=\"ruby-comment cmt\"># :monitors )</span>\n\
394: <span class=\"ruby-identifier\">members</span> = <span class=\"ruby-constant\">SignatureStruct</span>.<span class=\"ruby-identifier\">members</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">m</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">m</span>.<span class=\"ruby-identifier\">intern</span>}\n\
395: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">SignatureStruct</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">rawsig</span>.<span class=\"ruby-identifier\">values_at</span>(<span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">members</span>) )\n\
396: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Signature lookup: look for either a constant or an instance variable of the
class that contains the raw <a href="Applet.html#M000559">signature</a>
hash, and convert it to an Arrow::Applet::SignatureStruct object.
</p>
params: ()
- visibility: public
aref: M000556
name: method_added
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/arrow/applet.rb, line 290</span>\n\
290: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">method_added</span>( <span class=\"ruby-identifier\">sym</span> )\n\
291: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-regexp re\">/^(\\w+)_action$/</span>.<span class=\"ruby-identifier\">match</span>( <span class=\"ruby-identifier\">sym</span>.<span class=\"ruby-identifier\">to_s</span> ) <span class=\"ruby-operator\">&&</span>\n\
292: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">instance_method</span>( <span class=\"ruby-identifier\">sym</span> ).<span class=\"ruby-identifier\">arity</span>.<span class=\"ruby-identifier\">zero?</span>\n\
293: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ScriptError</span>, <span class=\"ruby-node\">"Inappropriate arity for #{sym}"</span>, <span class=\"ruby-identifier\">caller</span>(<span class=\"ruby-value\">1</span>)\n\
294: <span class=\"ruby-keyword kw\">end</span>\n\
295: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Method definition callback: Check newly-defined action methods for
appropriate arity.
</p>
params: ( sym )
- visibility: public
aref: M000563
name: new
sourceco