Module Kernel
In: lib/merb-core/core_ext/kernel.rb

Methods

Public Instance methods

Parameters

i<Fixnum>:The caller number. Defaults to 1.

Returns

Array[Array]:The file, line and method of the caller.

Examples

  __caller_info__(1)
    # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']

Parameters

file<String>:The file to read.
line<Fixnum>:The line number to look for.
size<Fixnum>:Number of lines to include above and below the the line to look for. Defaults to 4.

Returns

Array[Array]:Triplets containing the line number, the line and whether this was the searched line.

Examples

 __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # =>
  [
    [ 120, "  def check_suspend",                               false ],
    [ 121, "    return if Thread.critical",                     false ],
    [ 122, "    while (Thread.critical = true; @suspend_next)", true  ],
    [ 123, "      DEBUGGER__.waiting.push Thread.current",      false ],
    [ 124, "      @suspend_next = false",                       false ]
  ]

Takes a block, profiles the results of running the block specified number of times and generates HTML report.

Parameters

name<~to_s>:The file name. The result will be written out to Merb.root/"log/#{name}.html".
min<Fixnum>:Minimum percentage of the total time a method must take for it to be included in the result. Defaults to 1.

Returns

String:The result of the profiling.

Notes

Requires ruby-prof (sudo gem install ruby-prof)

Examples

  __profile__("MyProfile", 5, 30) do
    rand(10)**rand(10)
    puts "Profile run"
  end

Assuming that the total time taken for puts calls was less than 5% of the total time to run, puts won‘t appear in the profile report. The code block will be run 30 times in the example above.

Define debugger method so that code even works if debugger was not requested. Drops a note to the logs that Debugger was not available.

Loads both gem and library dependencies that are passed in as arguments. Execution is deferred to the Merb::BootLoader::Dependencies.run during bootup.

Parameters

*args<String, Hash, Array>:The dependencies to load.

Loads the given string as a gem. Execution is deferred to the Merb::BootLoader::Dependencies.run during bootup.

Parameters

name<String>:The name of the gem to load.
*ver<Gem::Requirement, Gem::Version, Array, ~to_str>:Version requirements to be passed to Gem.activate.

Checks that the given objects quack like the given conditions.

Parameters

opts<Hash>:Conditions to enforce. Each key will receive a quacks_like? call with the value (see Object#quacks_like? for details).

Raises

ArgumentError:An object failed to quack like a condition.

Extracts an options hash if it is the last item in the args array. Used internally in methods that take *args.

Parameters

args<Array>:The arguments to extract the hash from.

Examples

  def render(*args,&blk)
    opts = extract_options_from_args!(args) || {}
    # [...]
  end

Loads both gem and library dependencies that are passed in as arguments.

Parameters

*args<String, Hash, Array>:The dependencies to load.

Notes

Each argument can be:

String:Single dependency.
Hash:Multiple dependencies where the keys are names and the values versions.
Array:Multiple string dependencies.

Examples

dependencies "RedCloth" # Loads the the RedCloth gem dependencies "RedCloth", "merb_helpers" # Loads RedCloth and merb_helpers dependencies "RedCloth" => "3.0" # Loads RedCloth 3.0

Loads the given string as a gem.

Parameters

name<String>:The name of the gem to load.
*ver<Gem::Requirement, Gem::Version, Array, ~to_str>:Version requirements to be passed to Gem.activate.

Notes

If the gem cannot be found, the method will attempt to require the string as a library.

This new version tries to load the file via ROOT/gems first before moving off to the system gems (so if you have a lower version of a gem in ROOT/gems, it‘ll still get loaded).

Registers ORM at generator scope.

Parameters

orm<~to_sym>:ORM alias, like :activerecord, :datamapper or :sequel.

Register test framework at generator scope. Currently Merb has plugins to support RSpec and Test::Unit.

Parameters

test_framework<Symbol>:The test framework to check. Currently only supports :rspec and :test_unit but the check is performed before registration if you use API.

Use to check whether given ORM already registred at generator scope

Parameters

orm<~to_sym>:ORM alias, like :activerecord, :datamapper or :sequel.

Returns

Boolean:true if ORM is already registred, false otherwise

Does a basic require, and prints a message if an error occurs.

Parameters

library<~to_s>:The library to attempt to include.
message<String>:The error to add to the log upon failure. Defaults to nil.

Check whether Merb supports test framework. Currently Merb has plugins to support RSpec and Test::Unit.

Parameters

test_framework<Symbol>:The test framework to check. Currently only supports :rspec and :test_unit.

Used in Merb.root/config/init.rb to tell Merb which ORM (Object Relational Mapper) you wish to use. Currently Merb has plugins to support ActiveRecord, DataMapper, and Sequel.

Parameters

orm<~to_s>:The ORM to use.

Examples

  # This line goes in dependencies.yml
  use_orm :datamapper

  # This will use the DataMapper generator for your ORM
  $ ruby script/generate model MyModel

Used in Merb.root/config/init.rb to tell Merb which testing framework to use. Currently Merb has plugins to support RSpec and Test::Unit.

Parameters

test_framework<Symbol>:The test framework to use. Currently only supports :rspec and :test_unit.

Examples

  # This line goes in dependencies.yml
  use_test :rspec

  # This will now use the RSpec generator for tests
  $ ruby script/generate controller MyController

[Validate]