### Home Classes Methods

### In Files

- lib/merb-core/core_ext/kernel.rb
- lib/merb-core/test/test_ext/rspec.rb

### Methods

- #__caller_info__
- #__caller_lines__
- #__profile__
- #debugger
- #dependencies
- #dependency
- #enforce!
- #extract_options_from_args!
- #given
- #use_orm
- #use_template_engine
- #use_test
- #use_testing_framework

### Files

- CHANGELOG
- LICENSE
- README
- TODO

### Class/Module Index

Quicksearch

- Merb
- Merb::AbstractController
- Merb::AcceptType
- Merb::AuthenticationMixin
- Merb::AuthenticationMixin::BasicAuthentication
- Merb::BootLoader
- Merb::BootLoader::AfterAppLoads
- Merb::BootLoader::BackgroundServices
- Merb::BootLoader::BeforeAppLoads
- Merb::BootLoader::BuildFramework
- Merb::BootLoader::ChooseAdapter
- Merb::BootLoader::Cookies
- Merb::BootLoader::Defaults
- Merb::BootLoader::Dependencies
- Merb::BootLoader::DropPidFile
- Merb::BootLoader::LoadClasses
- Merb::BootLoader::Logger
- Merb::BootLoader::MimeTypes
- Merb::BootLoader::MixinSession
- Merb::BootLoader::RackUpApplication
- Merb::BootLoader::ReloadClasses
- Merb::BootLoader::ReloadClasses::TimedExecutor
- Merb::BootLoader::Router
- Merb::BootLoader::SetupSession
- Merb::BootLoader::SetupStubClasses
- Merb::BootLoader::Templates
- Merb::ConditionalGetMixin
- Merb::Config
- Merb::Config::ConfigBlock
- Merb::Const
- Merb::Controller
- Merb::ControllerExceptions
- Merb::ControllerExceptions::Accepted
- Merb::ControllerExceptions::ActionNotFound
- Merb::ControllerExceptions::BadGateway
- Merb::ControllerExceptions::BadRequest
- Merb::ControllerExceptions::Base
- Merb::ControllerExceptions::ClientError
- Merb::ControllerExceptions::Conflict
- Merb::ControllerExceptions::Continue
- Merb::ControllerExceptions::Created
- Merb::ControllerExceptions::ExpectationFailed
- Merb::ControllerExceptions::Forbidden
- Merb::ControllerExceptions::GatewayTimeout
- Merb::ControllerExceptions::Gone
- Merb::ControllerExceptions::HTTPVersionNotSupported
- Merb::ControllerExceptions::Informational
- Merb::ControllerExceptions::InternalServerError
- Merb::ControllerExceptions::LayoutNotFound
- Merb::ControllerExceptions::LengthRequired
- Merb::ControllerExceptions::MethodNotAllowed
- Merb::ControllerExceptions::MovedPermanently
- Merb::ControllerExceptions::MovedTemporarily
- Merb::ControllerExceptions::MultiPartParseError
- Merb::ControllerExceptions::MultipleChoices
- Merb::ControllerExceptions::NoContent
- Merb::ControllerExceptions::NonAuthoritativeInformation
- Merb::ControllerExceptions::NotAcceptable
- Merb::ControllerExceptions::NotFound
- Merb::ControllerExceptions::NotImplemented
- Merb::ControllerExceptions::NotModified
- Merb::ControllerExceptions::OK
- Merb::ControllerExceptions::PartialContent
- Merb::ControllerExceptions::PaymentRequired
- Merb::ControllerExceptions::PreconditionFailed
- Merb::ControllerExceptions::ProxyAuthenticationRequired
- Merb::ControllerExceptions::Redirection
- Merb::ControllerExceptions::RequestEntityTooLarge
- Merb::ControllerExceptions::RequestRangeNotSatisfiable
- Merb::ControllerExceptions::RequestTimeout
- Merb::ControllerExceptions::RequestURITooLarge
- Merb::ControllerExceptions::ResetContent
- Merb::ControllerExceptions::SeeOther
- Merb::ControllerExceptions::ServerError
- Merb::ControllerExceptions::ServiceUnavailable
- Merb::ControllerExceptions::Successful
- Merb::ControllerExceptions::SwitchingProtocols
- Merb::ControllerExceptions::TemplateNotFound
- Merb::ControllerExceptions::TemporaryRedirect
- Merb::ControllerExceptions::Unauthorized
- Merb::ControllerExceptions::UnsupportedMediaType
- Merb::ControllerExceptions::UseProxy
- Merb::ControllerMixin
- Merb::CookieSession
- Merb::CookieSession::CookieOverflow
- Merb::CookieSession::TamperedWithCookie
- Merb::Cookies
- Merb::CookiesMixin
- Merb::CookiesMixin::RequestMixin
- Merb::Counter
- Merb::Dispatcher
- Merb::Dispatcher::DefaultException
- Merb::Dispatcher::DefaultExceptionHelper
- Merb::GlobalHelpers
- Merb::InlineTemplates
- Merb::Logger
- Merb::MemcacheSession
- Merb::MemcacheStore
- Merb::MemorySession
- Merb::MemorySessionStore
- Merb::Parse
- Merb::Plugins
- Merb::Rack
- Merb::Rack::AbstractAdapter
- Merb::Rack::Adapter
- Merb::Rack::Application
- Merb::Rack::ConditionalGet
- Merb::Rack::Console
- Merb::Rack::ContentLength
- Merb::Rack::DeferrableMiddleware
- Merb::Rack::Ebb
- Merb::Rack::EventedMongrel
- Merb::Rack::FastCGI
- Merb::Rack::Handler
- Merb::Rack::Handler::Mongrel
- Merb::Rack::Head
- Merb::Rack::Helpers
- Merb::Rack::Irb
- Merb::Rack::Middleware
- Merb::Rack::Mongrel
- Merb::Rack::PathPrefix
- Merb::Rack::Profiler
- Merb::Rack::Runner
- Merb::Rack::Static
- Merb::Rack::StreamWrapper
- Merb::Rack::SwiftipliedMongrel
- Merb::Rack::Thin
- Merb::Rack::ThinTurbo
- Merb::Rack::Tracer
- Merb::Rack::WEBrick
- Merb::RenderMixin
- Merb::RenderMixin::ClassMethods
- Merb::Request
- Merb::ReservedError
- Merb::Responder
- Merb::ResponderMixin
- Merb::ResponderMixin::ClassMethods
- Merb::ResponderMixin::ContentTypeAlreadySet
- Merb::Router
- Merb::Router::Behavior
- Merb::Router::Behavior::Error
- Merb::Router::Behavior::Proxy
- Merb::Router::CachedProc
- Merb::Router::GenerationError
- Merb::Router::NotCompiledError
- Merb::Router::Resources
- Merb::Router::RouteNotFound
- Merb::Server
- Merb::Session
- Merb::SessionContainer
- Merb::SessionMixin
- Merb::SessionMixin::NoSessionContainer
- Merb::SessionMixin::RequestMixin
- Merb::SessionMixin::RequestMixin::ClassMethods
- Merb::SessionMixin::SessionOverflow
- Merb::SessionStoreContainer
- Merb::System
- Merb::System::PortablePoller
- Merb::Template
- Merb::Template::Erubis
- Merb::Template::Erubis::Mixin
- Merb::Test
- Merb::Test::ControllerHelper
- Merb::Test::Cookie
- Merb::Test::CookieJar
- Merb::Test::ExampleGroup
- Merb::Test::Helpers
- Merb::Test::MakeRequest
- Merb::Test::Matchers
- Merb::Test::MultipartRequestHelper
- Merb::Test::MultipartRequestHelper::FileParam
- Merb::Test::MultipartRequestHelper::Param
- Merb::Test::MultipartRequestHelper::Post
- Merb::Test::RequestHelper
- Merb::Test::RequestHelper::CookieJar
- Merb::Test::RequestHelper::FakeRequest
- Merb::Test::RouteHelper
- Merb::Test::Rspec
- Merb::Test::Rspec::ControllerMatchers
- Merb::Test::Rspec::ControllerMatchers::BeError
- Merb::Test::Rspec::ControllerMatchers::BeRedirect
- Merb::Test::Rspec::ControllerMatchers::Provide
- Merb::Test::Rspec::RouteMatchers
- Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Merb::Test::Rspec::RouteMatchers::RouteToMatcher
- Merb::Test::ViewHelper
- Merb::Test::WebratHelper
- Merb::Worker
- Erubis
- Erubis::Basic
- Erubis::Basic::Converter
- Erubis::BlockAwareEnhancer
- Erubis::BlockAwareEruby
- Erubis::MEruby
- Spec
- Spec::Matchers
- Spec::Matchers::MatcherDSL
- Spec::Runner
- Spec::Runner::Formatter
- Spec::Runner::Formatter::BaseTextFormatter
- Gem
- Gem::Dependency
- Hpricot
- Hpricot::Elem
- Mongrel
- Mongrel::HttpResponse
- Class
- Exception
- Hash
- Kernel
- MemCache
- Memcached
- Object
- String
- Time

No matching classes.

# Kernel

### Public Instance Methods

__caller_info__(i = 1) click to toggle source

@param i<Fixnum> The caller number. Defaults to 1.

@return <Array> The file, line and method of the caller.

@example

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

:api: private

    # File lib/merb-core/core_ext/kernel.rb, line 118
    def __caller_info__(i = 1)
      file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
    end

__caller_lines__(file, line, size = 4) click to toggle source

@param file<String> The file to read. @param line<Fixnum> The line number to look for. @param size<Fixnum>

    Number of lines to include above and below the the line to look for.
    Defaults to 4.

@return <Array>

    Triplets containing the line number, the line and whether this was the
    searched line.

@example

    __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 ]
      ]

:api: private

    # File lib/merb-core/core_ext/kernel.rb, line 143
    def __caller_lines__(file, line, size = 4)
      line = line.to_i
      if file =~ /\(erubis\)/
        yield :error, "Template Error! Problem while rendering", false
      elsif !File.file?(file) || !File.readable?(file)
        yield :error, "File `#{file}' not available", false
      else
        lines = File.read(file).split("\n")
        first_line = (f = line - size - 1) < 0 ? 0 : f

        if first_line.zero?
          new_size = line - 1
          lines = lines[first_line, size + new_size + 1]
        else
          new_size = nil
          lines = lines[first_line, size * 2 + 1]
        end

        lines && lines.each_with_index do |str, index|
          line_n = index + line
          line_n = (new_size.nil?) ? line_n - size : line_n - new_size
          yield line_n, str.chomp
        end
      end
    end

__profile__(name, min=1, iter=100) click to toggle source

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

@param name<to_s>

    The file name. The result will be written out to
    Merb.root/"log/#{name}.html".

@param min<Fixnum>

    Minimum percentage of the total time a method must take for it to be
    included in the result. Defaults to 1.

@return <String>

    The result of the profiling.

@note

    Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)

@example

    __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.

:api: private

    # File lib/merb-core/core_ext/kernel.rb, line 196
    def __profile__(name, min=1, iter=100)
      require 'ruby-prof' unless defined?(RubyProf)
      return_result = ''
      result = RubyProf.profile do
        iter.times{return_result = yield}
      end
      printer = RubyProf::GraphHtmlPrinter.new(result)
      path = File.join(Merb.root, 'log', "#{name}.html")
      File.open(path, 'w') do |file|
        printer.print(file, {:min_percent => min,
                        :print_file => true})
      end
      return_result
    end

debugger() click to toggle source

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

    # File lib/merb-core/core_ext/kernel.rb, line 247
    def debugger
      Merb.logger.info! "\n***** Debugger requested, but was not " +
        "available: Start server with --debugger " +
        "to enable *****\n"
    end

dependencies(*args) click to toggle source

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

:api: public @deprecated

    # File lib/merb-core/core_ext/kernel.rb, line 23
    def dependencies(*args)
      args.map do |arg|
        case arg
        when String then dependency(arg)
        when Hash then arg.map { |r,v| dependency(r, v) }
        when Array then arg.map { |r| dependency(r) }
        end
      end
      nil
    end

dependency(name, *opts, &blk) click to toggle source

Loads the given string as a gem.

:api: public @deprecated

    # File lib/merb-core/core_ext/kernel.rb, line 6
    def dependency(name, *opts, &blk)
      warn "DEPRECATED: Use bundler to setup and load dependency #{name}."
      options = opts.last.is_a?(Hash) ? opts.pop : {}
      version = opts.pop unless opts.empty?
      if version
        warn "DEPRECATED: You want to load gem #{name} with specific version "             "#{version}. This feature is not supported and the LATEST VERSION "             "OF THE GEM WILL BE LOADED."
      end
      require (options[:require_as] ? options[:require_as] : name)
      nil
    end

enforce!(opts = {}) click to toggle source

Checks that the given objects quack like the given conditions.

@param opts<Hash>

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

@raise <ArgumentError>

    An object failed to quack like a condition.

:api: public

    # File lib/merb-core/core_ext/kernel.rb, line 237
    def enforce!(opts = {})
      opts.each do |k,v|
        raise ArgumentError, "#{k.inspect} doesn't quack like #{v.inspect}" unless k.quacks_like?(v)
      end
    end

extract_options_from_args!(args) click to toggle source

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

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

@example

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

:api: public

    # File lib/merb-core/core_ext/kernel.rb, line 223
    def extract_options_from_args!(args)
      args.pop if (args.last.instance_of?(Hash) || args.last.instance_of?(Mash))
    end

given(*args, &example_group_block) click to toggle source

    # File lib/merb-core/test/test_ext/rspec.rb, line 3
    def given(*args, &example_group_block)
      args << {} unless Hash === args.last
      params = args.last

      params[:shared] = true

      describe(*args) do
        prepend_before(:each) do
          self.instance_eval(&example_group_block)
        end
      end
    end

use_orm(orm) click to toggle source

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<Symbol> | The ORM to use.

#### Returns

nil

#### Example

    use_orm :datamapper

    # This will use the DataMapper generator for your ORM
    $ merb-gen model ActivityEvent

#### Notes

    If for some reason this is called more than once, latter
    call takes over other.

:api: public

    # File lib/merb-core/core_ext/kernel.rb, line 55
    def use_orm(orm)
      Merb.orm = orm
      nil
    end

use_template_engine(template_engine) click to toggle source

Used in Merb.root/config/init.rb to tell Merb which template engine to prefer.

#### Parameters

template_engine<Symbol>

    The template engine to use.

#### Returns

nil

#### Example

    use_template_engine :haml

    # This will now use haml templates in generators where available.
    $ merb-gen resource_controller Project

:api: public

    # File lib/merb-core/core_ext/kernel.rb, line 103
    def use_template_engine(template_engine)
      Merb.template_engine = template_engine
      nil
    end

use_test(*args) click to toggle source

    # File lib/merb-core/core_ext/kernel.rb, line 82
    def use_test(*args)
      use_testing_framework(*args)
    end

use_testing_framework(test_framework) click to toggle source

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.

#### Returns

nil

#### Example

    use_test :rspec

    # This will now use the RSpec generator for tests
    $ merb-gen model ActivityEvent

:api: public

    # File lib/merb-core/core_ext/kernel.rb, line 77
    def use_testing_framework(test_framework)
      Merb.test_framework = test_framework
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.