Module Boson::Inspector

  1. lib/boson/inspector.rb

Scrapes and processes method attributes with the inspectors (MethodInspector, CommentInspector and ArgumentInspector) and hands off the data to FileLibrary objects.

Method Attributes

Method attributes refer to (commented) Module methods placed before a command’s method in a FileLibrary module:

module SomeMod
   # @render_options :fields=>%w{one two}
   # @config :alias=>'so'
   options :verbose=>:boolean
   # Something descriptive perhaps
   def some_method(opts)
     # ...

Method attributes serve as configuration for a method’s command. Available method attributes:

  • config: Hash to define any command attributes (see
  • desc: String to define a command’s description for a command. Defaults to first commented line above a method.
  • options: Hash to define an OptionParser object for a command’s options.
  • render_options: Hash to define an OptionParser object for a command’s local/global render options (see View).

When deciding whether to use commented or normal Module methods, remember that commented Module methods allow independence from Boson (useful for testing). See CommentInspector for more about commented method attributes.


public instance

  1. add_method_data_to_library
  2. disable
  3. enable


enabled [R]

Public instance methods

add_method_data_to_library (library)

Adds method attributes scraped for the library’s module to the library’s commands.

[show source]
# File lib/boson/inspector.rb, line 60
    def add_method_data_to_library(library)
      @commands_hash = library.commands_hash
      @library_file = library.library_file
      MethodInspector.current_module = library.module
      @store =
disable ()

Disable scraping method data.

[show source]
# File lib/boson/inspector.rb, line 51
    def disable
      ::Module.module_eval %[
        Boson::MethodInspector::METHODS.each {|e| remove_method e }
        alias_method :method_added, :_old_method_added
      @enabled = false
enable ()

Enable scraping by overridding method_added to snoop on a library while it’s loading its methods.

[show source]
# File lib/boson/inspector.rb, line 32
    def enable
      @enabled = true
      body = {|e|
        %[def #{e}(val)
            Boson::MethodInspector.#{e}(self, val)
      }.join("\n") +
        def new_method_added(method)
          Boson::MethodInspector.new_method_added(self, method)

        alias_method :_old_method_added, :method_added
        alias_method :method_added, :new_method_added
    ::Module.module_eval body