Skip to content

Instantly share code, notes, and snippets.

@wycats
Created August 8, 2008 22:30
Show Gist options
  • Save wycats/4632 to your computer and use it in GitHub Desktop.
Save wycats/4632 to your computer and use it in GitHub Desktop.
undefined
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.
merb-core is a new branch of Merb (also referred to as merb-next or the 0.9 series) which aims to provide a stable, stripped down API for a future Merb 1.0 release.
This branch is based off the 0.5 release series but with significant rewrites.
Goals of this release:
* Stabilize the @public interface methods to provide for a more consistent application development experience.
* Remove features until nothing except a central application API is left
* Improve comments on methods using a standard documentation methodology as described in DOCUMENTATION_STANDARDS
* Separate the tests into two sections... "private" and "public"
* Public methods are methods tagged with @public that will be part of the standard, stable Merb API
* Private methods are implementation methods that might
* Implement a new render API
* Build more extensions to regain selected features when needed
To familiarize yourself with how a merb-core application might look,
use merb-gen (from merb-more) to generate a few apps:
$ merb-gen app myapp # a "normal" merb app
$ merb-gen app myapp --flat # a flattened app
$ merb-gen app myapp --very-flat # a single-file app
require "rubygems"
require "rbench"
# arr = %w(hello my name is Merb)
#
# Benchmark.warmer(100_000) do
# report "|" do
# arr | %w(hello my name is Mrs. Merb)
# end
# report "+" do
# (arr + %w(hello my name is Mrs. Merb)).uniq
# end
# end
require "set"
HSH = {:foo => true, :bar => true, :baz => true}
SET = Set.new
SET << :foo << :bar << :baz
def included?(key)
HSH.include?(key)
end
RBench.run(1_000_000) do
column :hash
column :set
column :indirection
report "includes" do
hash { HSH.include?(:foo) }
set { SET.include?(:foo) }
indirection { included?(:foo) }
end
report "not included" do
hash { HSH.include?(:bam) }
set { SET.include?(:bam) }
indirection { included?(:bam) }
end
end
# Results |
# ----------------------
# hash 0.078 |
# set 0.171 |
The Merb boot process starts when you run the Merb binary, which calls `Merb.start`. Merb.start performs the
following tasks:
list.
* Loads merb.yml from the root directory or config directory and puts them in the Merb::Config hash
* Parses config arguments from the command-line and adds them to the Merb::Config hash
* Runs the BootLoaders (see below)
* Starts the Merb Rack adapter
The BootLoader is a configurable process, which, by default, runs the following processes:
deflist.
Environment: Sets the Merb environment based on any -e flag passed the merb binary
BuildFramework: Set the framework paths, which can either be set in the Merb::Config[:framework]
variable or defaults to the paths described below.
Dependencies: Load dependencies.rb, which should include any plugins that will be loaded, as well
as an after_app_loaded hook.
Logger: Set up the logger in the `Merb.dir_for(:log)` directory. In test mode, it will be called
`test_logger`. In other modes, it will be set to `merb.#{pid}.log`. The log level will default
to `info` but can be specified via the Merb::Config[:log_level] option.
LoadRouter: The router is loaded from `Merb.dir_for(:config)/router.rb`.
LoadClasses: Files in all of the load paths are `require`d, and classes added during the load of
each files are tracked so they can be removed later during the reloading process.
Templates: All templates under the `_template_root` of any loaded controllers, as well as all
templates under `Merb.dir_for(:view)` are registered as inlined templates.
MimeTypes: Register all MimeTypes (see below for defaults).
AfterAppLoads: Call any `after_app_loads` hooks that were registered in dependencies.rb
MixinSessionContainer: Register the session types and set the app to use one if
`Merb::Config[:session_type]` is set.
ChooseAdapter: Set `Merb.adapter` to be the adapter chosen via Merb::Config[:adapter] (which
can be specified via the `-a foo` command-line parameter).
RackUpApplication: Set up a default rack application. Alternatively, allow for additional configuration
in `Merb.dir_for(:config)/rack.rb`, which will be evaluated in the context of a Rack::Builder.new
block.
ReloadClasses: If Merb::Config[:reload_classes] is set, begin the process of reloading classes
every time a class is modified.
deflist: Default Framework Paths.
application: Merb.root/app/controller/application.rb
config: Merb.root/config
lib: Merb.root/lib
log: Merb.root/log
view: Merb.root/app/views
model: Merb.root/app/models
controller: Merb.root/app/controllers
helper: Merb.root/app/helpers
mailer: Merb.root/app/mailers
part: Merb.root/app/parts
deflist: MimeTypes.
\:all: no transform, */*
\:yaml: to_yaml, application/x-yaml or text/yaml
\:text: to_text, text/plain
\:html: to_html, text/html or application/xhtml+xml or application/html
\:xml: to_xml, application/xml or text/xml or application/x-xml, adds "Encoding: UTF-8" response header
\:js: to_json, text/javascript ot application/javascript or application/x-javascript
\:json: to_json, application/json or text/x-json
require "rubygems"
require "rbench"
require "erb"
def using_caller(&blk)
caller[0]
end
def evaller(&blk)
eval("defined? _erbout", blk)
end
require "inline"
module Kernel
inline do |builder|
builder.include %{"env.h"}
builder.include %{"node.h"}
builder.add_compile_flags %{-O3}
builder.c_raw <<-C
VALUE c_trick() {
return ruby_frame->prev->node->nd_file == "(erb)" ? Qtrue : Qfalse;
}
C
end
end
CALLER = ERB.new("<% using_caller do %>Hello<% end %>")
EVALLER = ERB.new("<% evaller do %>Hello<% end %>")
C_TRICK = ERB.new("<% c_trick do %>Hello<% end %>")
RBench.run(10_000) do
report("caller") { CALLER.result(binding) }
report("evaller") { EVALLER.result(binding) }
report("c_trick") { C_TRICK.result(binding) }
end
# Results |
# -------------------------
# caller 0.312 |
# evaller 0.213 |
# c_trick 0.160 |
== 0.9.3 "We Sold Our Soul for Rock 'n' Roll" 2008-05-03
* Added render(template_path) feature to view specs.
* add mutex around compiled statement generation in the router so reloading doesn't step
* BootLoader::LoadClasses now logs the actual exceptions
* Added String#unescape_regexp for usage in Router::Route#generate
* Added Time#to_json to Core Extensions so JSON formatted output for Time is ISO 8601 compatible
* redo stream_file to (hopefully) work
* _dispatch returns @body
* Refactored Merb::AbstractController.layout class method
* Fixed lurking infinite loop with not so common formats and ExceptionController
* HTTP Basic authentication based on Rack
* added dispatch helper for http basic authentication
* added support and specs for http basic authorization
* modified specs to test a route restriction based on the request method
* Added ability to specify :format in url() for named routes
* Added thrown_content? predicate method for use in templates.
* pass arguments to filters
* Fix cookie sessions bug where you could not properly delete a cookie
* Standardises the call to set_cookie to use the set_cookie method in cookies.rb by default
* added HasContent matcher
* Added \- to String.unescape_regexp
* Changed the display method to handle options properly, so that passing :layout => :false works.
* Added error message for when a content_type is requested but not provided
* added delete action to docs
* deferred?(env) now works with thin and ebb.
* If deferred_actions are empty? we want a regex that will never match.
* Fix example in Merb::Test::RequestHelper#request documentation.
* Unify &block documentation across Merb::Test::RequestHelper
* Add spec command run options to run_specs. Add tasks for profiled spec run.
* Report total spec suite run time.
* Use RSPEC_OPTS environment variable to override default spec run options.
* Better formatting of spec suite run benchmark with good old sprintf.
* Fix a nasty String#camel_case bug revealed but new shiny spec for String extensions.
* Remove helper that duplicated String#camel_case functionality, update the rest of spec suite.
* Split 'misc' examples group in Kernel extensions spec: each method should have a separate group
* Split Kernel#use_orm guts into a bunch of smaller methods. Document those.
* Kernel#already_registred_orm? is a sucky name. Make it Kernel#registred_orm?. Yay.
* Split Kernel#use_test into smaller methos. Document them. Add specs for them beforehand.
* Use a constant for sleep time in reloading specs
* Use @ in publicity markers in RDoc.
* Remove InvalidPathConversion exception: it is used nowhere in the core.
* A bit clearer --init-file option description.
* Be clear about what is the default init file Merb uses in RDoc.
* hopefully the last fix for session fixation, woot woot
* Provide hook for param filtering
* Give useful information when no template is found for a partial
* Adds a question method to determine environment. eg Merb.env?(:production)
* Make #display method pass all 'unknown' options to serialization method.
* Add Object#in? for checking array inclusion
* Update Kernel#__profile__ documentation.
* Adding support for pidfile setting with cluster nodes setting.
* Updating pidfile cluster fix to handle any extension.
* Fix for kill so that cli options are read and handled before kill is actually called.
* Refactored Exception status handling/inheritance (it actually works now!)
* Replaced remaining ::STATUS constant references to .status method calls
* Append the content_type to the given :template option for render()
* Fix bug in --very-flat (allow direct inheritance from Merb::Controller)
* Show merb usage if first argument is not a switch
* Adding missing info about ebb adapter.
* completed spec to Merb::Logger#new
* Added Provide matcher class, so you can do "controller.should provide( :xml )" in your specs.
* Added support for multiple keys to designate a resource. For use with Datamapper composite keys
* Ensure that Merb::Logger doesn't try to close terminal streams.
* Remove redundant unescape for cookie string
* Added handling of INT signal for Merb server in foreground mode
* params array serialization
* Fixing pidfiles glob on cluster and pidfile argument
* test request helpers support namespaced routes
* Testing Merb::Test::RequestHelper#request method to properly handle namespaced routes
* Provide opts for alternate rackup config path.
* Add new -R/--rackup option to the full(-ish) list of options.
* Make change_priveledge actually work
* Allow http status to be a symbol - refactored String snake_case method
* removing __app_file_trace__ since it doesn't work.
== 0.9.2 "appropriate response to reality" 2008-03-24
* removed Merb.logger calls due to the fact the bootloader did not ran by now and it is not initialized.
* use __send__ rather than send
* Fixed exception setting route when route_index is nil
* memoize the raw_post body after it's called once
* fix Request#raw_post to respect bodies with no rewind method
* remove Kernel#requires it wasn't being used.
* Move fixation to post initialize
* add specs for does_not_provide
* Add specs for action-level only_provides
* Make controller.route work
* Update Ebb adapter to work with latest Ebb 0.1.0 [Ry Dahl]
* fix PATH_INFO bug for fcgi
* Rename url_with_host to absolute_url
* Add url_with_host() and allow params to be pushed into FCGI adapter
* More correct to_json of dictionary.
* Modify dispatcher to be sane to XHRs; add to_json to dictionaries.
* Added html_escape around the exception.message in the show details section.
* Fixed bug not allowing have_tag to be called without a attribute hash, even when one is not desired
* refactor and clean up Merb::BootLoader::Dependencies [James Herdman]
* Merb::BootLoader::LoadClasses should keep unique list of classes
* Logger now works as expected, fixed ReloadClasses bootloader
* Fixes cookie sessions when the session is blanked out.
* catch_content should default to :for_layout
* Added --sandbox (-S) option for IRB console
* Added Merb.testing? method
* Fixes the dispatch_to request helper to conver the action name to a string.
* Added Merb.testing? method
* Fixed critical bug in LoadClasses BootLoader concerning reloading
* Important changes to the BootLoader process
* Added Kernel.load_dependencies method; better docs/comments.
* Bugfixes concerning BootLoader and load order in general
* fully qualify fcgi rack handler
* Set mongrel as default adapter unless other alternative options are specified
* Fix configuring session_id_key so that it works
* url(:foo, 3) should notice 3 is a Fixnum, and use it instead of 3.id
* make load order of core_ext explicit
* Modifies before/after in BootLoader to actually work.
* ix not-available vs. not-provided bug in content negotiation
* Fixed display bug which caused default error exception pages to improperly display drop-down twirly if the path name exceeded the line length.
* remove symbolize_keys! as we don't use it anywhere. by now..
* Rework bootloader to make more sense for flat apps (specifically framework load)
* More fixes to the flat autoloader
* remove custom_* resource route, use :member or :collection instead
* fix logger specs
* Fixes bug with framework not being defined.
* make sure logger bang! methods do not flush unless the proper log level is used.
* Updates the request spec to account for the new from_xml behaviour
* Adds specs and changes for compatibility with ActiveSupport. There is one caveat. It will not change YAML generated Hash keys to strings if they are defined as symbols as is currently the behaviour of ActiveSupport.
* update the logger. no longer accept an optional block to call.
* remove some vestigal config defaults
* Add rack adapter for Ebb, damn it's fast!
* coerce the port to an integer when starting mongrel (jruby compat)
* remove specs for dependency as they were broittle and not testing the right thing.
* Fixes #155 (_perform_content_negotiation doesn't find */* if it comes last in the accept header order, and nothing else matches)
* Changes use_test to wrap only the call to dependencies in the check for Merb.environment == "test"
== 0.9.1 "Some are half-wild, and some are just outlaws." 2008-02-29
* Put spec tasks into namespaces and method for specifying pnly a certain model/controller/view to run against
* As a last resort, look for */* in the formats before throwing NotAcceptable (TODO: Clean this up)
* Fix perform_content_negotiation to correctly handle :format in params. Fix render_* to correctly return the correct content_type.
* remove hooks.rb, they were premature and only used in one place
* fix evented mongrel to not go crazy
* Calling /foo.pdf should throw a 406 if :pdf is not a registered mime.
* touch up dispatcher a bit, remove some un-needed code from the hot path
* fix dispatcher to not parse the params twice, still supports request_params
* fix Exception in exception.html.erb
* moved rspec rake tasks into core. Added Merb.rakefiles, which is now used by Merb::Plugins.rakefiles. Changed Kernel#use_test to only load dependency arguments when Merb.env is nil or test.
* do not load test framework unless Merb.env == 'test'
* Use new Object.make_module to create the module instead of old hackish solution.
* Don't clear our mimes previously defined.
* Fixed clean task deleting everything in the lib folder
* Kernel#dependency requires gems/files in a before_app_loads block.
* Move dependency loading after framework and look for framework.rb
* Creates helper stub modules for controllers.
* fix blank path error.
* Cooler errors
* add named routes to error page
* updates to nested resources
* get autotest working for merb-core
* Symbolize params in route generation, to accomodate Mashes
* Fixes :status not working on strings.
* update thin adapter to newest way of silencing the log
* :format => :html possible in partials
* print request URI when "No routes match the request" error thrown
* fix merb -i
* Make Merb.start default to the runner adapter
* It's now possible to send binary data using the send_data method
and to specify the disposition, filename and type of the data being sent.
* Fix memcached session writes
* allow the setting of a custom session key
* Changed TemplateNotFound to stop so much confusion about incorrect
template locations because it doesn't include .*
* fix dropping of pid files in cluster and daemon mode
* Nested partials don't blow away locals.
* Better loading of classes
* Support concat and test capture/concat
* Added single key assignment to Merb.config
* Move url method from ControllerMixin to AbstractController for use in
Mailers and Parts etc.
* Merb.config now returns Merb::Config instead of the current
configuration hash.
* Added Merb.reload which reloads the framework classes.
* Adding Merb.env shorthand for Merb.environment
* Added a quaint Merb Configurator
* With bootloader order changes, environment was not getting loaded
* Fix cookie parsing from localhost, add spec
* Add support for multiple template roots
* Allow override of router.rb file in config
* Modify behavior of 'namespace' in the router
* Fix content negotiation for IE and its stupid accept header.
* Only serve static files when the HTTP method is GET or HEAD. Other
requests should still be handled by Merb.
* Add path_prefix support.
* Changes dispatch_to spec helper to yield the controller
* redo of load_dependency, after_app_loads callback, and Kernel changes
* Added Merb.logger.auto_flush
* Fix nested resource routing
* Do not drop PID file is not running as daemon or cluster
* Fixed problem with resources inside a namespace block
* Added support for dynamic layouts.
* adding conditional behaviour to filters :if and :unless
* Use the escape_xml from Erubis rather than rolling our own
* Add a merb.reload! command to the merb -i console.
* Get rid of StringScanner dependency.
* Fix render_then_call to support new streaming tech.
* Fix filter specs to respect append order of filters.
* check for empty string before calling to_sym on the format parameter
* fake requests are incorrectly loading controller classes with namespaces
* Fix the RubyGems monkeypatch by testing for Merb.root instead of looking in $"
* fix core spec dependency on merb_rspec
* Replace calls to puts with Merb.logger
* Fix problem with static files, use Proc === body
* Added file and line information for evals in router.rb.
== 0.9.0 "All you need, none you don't" 2008-02-13
* Developer Only Release
* Split merb into merb-core and merb-more
== 0.5.3 "Inexperienced With Girls" 2008-01-28
* Improved handling of models/controllers with dependencies
* Improved cluster starting/stopping
* Frozen script/merb should really work now
* Merb::Cookies is used for cookie jar purposes
* test_helper no longer assumes rspec mocking framework
* asset bundler handles strings and symbols
* render() now has an option for explicitly rendering an object
* Fixed annoying bug in exception rendering for 500 internal_server_error
* testing request helper accepts an option hash
== 0.5.2 "Great White North" 2008-01-14
* Make Merb.load_paths accessible for modification
* Fix issues with running frozen apps
== 0.5.1 "Electic Boogaloo" 2008-01-10
* Fix 0.5.0
== 0.5.0 "Thanks Zed" 2008-01-09
* Added asset bundling for Javascript and stylesheet files
== 0.4.2 "Surf's up." 2007-12-14
* Super-huge speed boost for rendering Erubis templates with partials
* Windows-specific fixes to Merb's Rakefile
* Blocking write is called when in development, test, Windows and jRuby environments and platforms.
* merb_helpers: form field labels are now explicit, huge documentation update, added select, fieldset, more helpers
* Fixed merb.show_routes within merb -i
* Fixed image_tag, css_include_tag, and js_include_tag to work with path_prefix
* Adds spec helper methods with_route and dispatch_to
* fix rakefile cfor cygwin
* add count with collection to partial()
* Form control mixin is deprecated Use merb_helpers plugin.
* add redirect matcher to rspec test helpers
* allow r.resource(:foo, :myparam => 42) resource routes pass on params to underlying match() call
* spit out error and help message if you call merb with no args
* get rid of dependency on mongrel for escape and unescape
* make sure not to use write_nonblock when logging to STDOUT
* Fixed image_tag, css_include_tag, and js_include_tag to work with path_prefix
* fix set_status to actually work, add docs,
* config/merb.yml is now correctly loaded from Rake and test environment - using Merb::Server.load_config
* added config option to disable loading of the JSON gem - still enabled by default
* don't raise if names local on a partial is nil
* Use svn export instead of checkout upon merb:freeze_from_svn
* Extracted url and other general methods out of ControllerMixin into GeneralControllerMixin
* fix caching of @_buffer in render, form_for
* Seperates spec helpers into the Merb::Test namespace to prevent spec methods leaking into specs
* Changes the spec url helper method to the same used in the controller
* Made Request#parse_multipart return an empty hash instead of nil if the request is not multipart
* Changes throw_content so that it can be called without a block
* Added :namespace option to routes.
== 0.4.1 "Faster Partials or Partially Faster?" 2007-11-12
* Fixed pluralization issues with generators
* Resource generators are much improved
* url() helper now supports nested resources
* url(:post, @post) observers @post.new_record? and adjusts accordingly
* Fixed bug with empty Accept headers
* Added config/boot.rb to load framework from gems or framework/ dir
* New partial() is much faster (and less buggy)
* render :partial no longer supported
* Add a buffered logger
* Fixes bug with parameterized actions on some platforms
* partial can now be called on collections:
* partial("widget", :with => @new_widgets, :as => "widget")
* SMTP mailer now supports non-AUTH setups
* set_status() can take symbolic codes like :not_found
* JRuby compat fixes
* Speed boost, esp. with rendering
* Fix spec_helper running against development database
* Fix major bug with sessions not working
== 0.4.0 "This ain't yo mommas merb" 2007-11-06
== 0.3.7 "Out of the basement" 2007-08-05
== 0.3.4 "Route fixer" 2007-05-31
== 0.3.3 "Hey buddy can you spare a route generator?" 2007-05-31
== 0.3.1 "The Fixed and the Furious" 2007-04-30
== 0.3.0 "The Fast and the Furious" 2007-04-28
== 0.2.0 "Accept your fate and respond_to change" 2007-03-18
== 0.1.0 "Generation Herb" 2007-01-18
== 0.0.9 "merb is the new black" 2007-01-14
== 0.0.8 "Merbivore" 2006-12-17
== 0.0.7 "Lean and mean merbing machine" 2006-11-29
== 0.0.6 "The Black Belt Release" 2006-11-09
== 0.0.5 "The getting real release" 2006-11-01
== 0.0.4 "The toddler phase" 2006-10-26
== 0.0.3 "the switchblade suicide release" 2006-10-17
== 0.0.2 "the quicksliver release" 2006-10-16
== 0.0.1 "The pocket rocket release" 2006-10-15
require "rubygems"
require "merb-core"
class Grandparent < Merb::Controller
end
class Parent < Grandparent
end
class Grandparent
class_inheritable_accessor :last_name, :_attribute
self._attribute = "1900"
end
class Child < Parent
end
describe Class, "#inheritable_accessor" do
after :each do
Grandparent.send(:remove_instance_variable, "@last_name") rescue nil
Parent.send(:remove_instance_variable, "@last_name") rescue nil
Child.send(:remove_instance_variable, "@last_name") rescue nil
end
it 'inherits unless overriden' do
Parent._attribute.should == "1900"
end
end
==== Configuration options
:session_id_cookie_only<Boolean>::
If true, sessions may be passed only through cookies. If false, they may also
be passed through the session_id_key query param. This might be necessary for
flash uploaders, which do not pass cookies with file uploads. This can be
used in conjunction with :query_string_whitelist.
:query_string_whitelist<Array[String]>::
A list of "controller/action" URLs that should allow session IDs to be passed
through the query string even if :session_id_cookie_only is set to true. We
recommend using session.regenerate after any controller making use of this
in case someone is trying a session fixation attack.
require "rubygems"
require "dm-core"
require "dm-validations"
require "pp"
DataMapper.setup(:default, "sqlite3::memory:")
class Category
include DataMapper::Resource
property :id, Serial
has n, :items
end
class Item
include DataMapper::Resource
property :id, Serial
property :category_id, Integer
belongs_to :category
end
DataMapper.auto_migrate!
Item.create(:category_id => 25)
Item.first.category
# class Parent
# include DataMapper::Resource
#
# property :id, Serial
# property :name, String
#
# def self.auto_migrate!(*args)
# nil
# end
# end
#
# class Child1 < Parent
# property :child_attr1, String
# validates_present :name
# end
#
# class Child2 < Parent
# property :child_attr2, String
# end
#
# DataMapper.auto_migrate!
#
# describe Parent do
# it "has an id" do
# Parent.properties.map {|x| x.name}.should include(:id)
# end
#
# it "doesn't have a child_attr1" do
# Parent.properties.map {|x| x.name}.should_not include(:child_attr1)
# end
#
# it "has a name non-nullable validation" do
# Parent.validators.contexts[:default].select do |obj|
# obj.field_name == :name
# end.any? {|v| v.is_a?(DataMapper::Validate::RequiredFieldValidator)}.
# should be_false
# end
# end
#
# describe Child1 do
# it "has an id" do
# Child1.properties.map {|x| x.name}.should include(:id)
# end
#
# it "has a child_attr1" do
# Child1.properties.map {|x| x.name}.should include(:child_attr1)
# end
#
# it "doesn't have a child_attr2" do
# Child1.properties.map {|x| x.name}.should_not include(:child_attr2)
# end
#
# it "has a name non-nullable validation" do
# Child1.validators.contexts[:default].select do |obj|
# obj.field_name == :name
# end.any? {|v| v.is_a?(DataMapper::Validate::RequiredFieldValidator)}.
# should be_true
# end
# end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
class Foo
define_method(:foo) do |x|
x
end
class_eval <<-EOS, __FILE__, __LINE__
def #{:bar}(x)
x
end
EOS
def baz(x)
x
end
end
Benchmark.bmbm do |x|
x.report("define_method") { TIMES.times {Foo.new.foo(10)} }
x.report("class_eval") { TIMES.times {Foo.new.bar(10)} }
x.report("def") { TIMES.times {Foo.new.baz(10)} }
end
Autotest.add_discovery do
"merbsource"
end
Every method should have documentation above the method definition that fits this basic model...
# Render the specified item, with the specified options.
#
# ==== Parameters
# thing<String, Symbol, nil>::
# The thing to render. This will default to the current action
# opts<Hash>:: An options hash (see below)
#
# ==== Options (opts)
# :format<Symbol>:: A registered mime-type format
# :template<String>::
# The path to the template relative to the template root
# :status<~to_i>::
# The status to send to the client. Typically, this would
# be an integer (200), or a Merb status code (Accepted)
# :layout<~to_s>::
# A layout to use instead of the default. This should be
# relative to the layout root. By default, the layout will
# be either the controller_name or application. If you
# want to use an alternative content-type than the one
# that the base template was rendered as, you will need
# to do :layout => “foo.#{content_type}” (i.e. “foo.json”)
#
# ==== Returns
# String:: The rendered template, including layout, if appropriate.
#
# ==== Raises
# TemplateNotFound::
# There is no template for the specified location.
#
# ==== Alternatives
# If you pass a Hash as the first parameter, it will be moved to
# opts and “thing” will be the current action
#
#—
# @public
def render(thing = nil, opts = {})
<snip>
end
require "rubygems"
require "rbench"
EMPTY = []
FULL = [1, 2, 3]
RBench.run(100_000) do
column :empty?
column :first
column :length
report "empty" do
empty? {EMPTY.empty?}
first {!EMPTY.first}
length {EMPTY.length == 0}
end
report "full" do
empty? {FULL.empty?}
first {!FULL.first}
length {FULL.length == 0}
end
end
require "rubygems"
require "rbench"
require "erb"
require "erubis"
module Erubis
module BlockAwareEnhancer
def add_preamble(src)
src << "@_buf = '';"
end
def add_postamble(src)
src << "\n" unless src[-1] == ?\n
src << "_buf\n"
end
def add_expr_literal(src, code)
unless code =~ /(do|\{)(\s*|[^|]*|)?\s*$/
src << ' _buf << (' << code << ').to_s;'
else
src << ' _buf << ' << code << "; "
end
end
end
class BlockAwareEruby < Eruby
include BlockAwareEnhancer
end
end
class Templates
attr_accessor :_buf
end
ERB.new("<%= 1 %><%= 2 %><%= 3 %>").def_method(Templates, "erb")
Erubis::Eruby.new("<%= 1 %><%= 2 %><%= 3 %>").def_method(Templates, "erubis")
p ERB.new("<%= 1 %><%= 2 %><%= 3 %>")
p Erubis::BlockAwareEruby.new("<%= 1 %><%= 2 %><%= 3 %>")
T = Templates.new
p T.erb
p T.erubis
RBench.run(1_000_000) do
report("erb") do
T.erb
end
report("erubis") do
T.erubis
end
end
require "rubygems"
require "erubis"
module Erubis
module Basic::Converter
def add_tailchar(src, tailchar)
end
def convert_input(src, input)
pat = @pattern
regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
pos = 0
is_bol = true # is beginning of line
input.scan(regexp) do |indicator, code, tailch, rspace|
match = Regexp.last_match()
len = match.begin(0) - pos
text = input[pos, len]
pos = match.end(0)
ch = indicator ? indicator[0] : nil
lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
is_bol = rspace ? true : false
add_text(src, text) if text && !text.empty?
## * when '<%= %>', do nothing
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
if ch == ?= # <%= %>
rspace = nil if tailch && !tailch.empty?
add_text(src, lspace) if lspace
add_expr(src, code, indicator)
add_text(src, rspace) if rspace
elsif ch == ?\# # <%# %>
n = code.count("\n") + (rspace ? 1 : 0)
if @trim && lspace && rspace
add_stmt(src, "\n" * n)
else
add_text(src, lspace) if lspace
add_stmt(src, "\n" * n)
add_text(src, rspace) if rspace
end
elsif ch == ?% # <%% %>
s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}"
add_text(src, s)
else # <% %>
if @trim && lspace && rspace
if respond_to?(:add_stmt2)
add_stmt2(src, "#{lspace}#{code}#{rspace}", tailch)
else
add_stmt(src, "#{lspace}#{code}#{rspace}")
end
else
add_text(src, lspace) if lspace
if respond_to?(:add_stmt2)
add_stmt2(src, code, tailch)
else
add_stmt(src, code)
end
add_text(src, rspace) if rspace
end
end
end
#rest = $' || input # ruby1.8
rest = pos == 0 ? input : input[pos..-1] # ruby1.9
add_text(src, rest)
end
end
module BlockAwareEnhancer
def add_preamble(src)
src << "_old_buf, @_erb_buf = @_erb_buf, ''; "
src << "@_engine = 'erb'; "
end
def add_postamble(src)
src << "\n" unless src[-1] == ?\n
src << "_ret = @_erb_buf; @_erb_buf = _old_buf; _ret.to_s;\n"
end
def add_text(src, text)
p escape_text(text)
src << " @_erb_buf.concat('" << escape_text(text) << "'); "
end
def add_expr_escaped(src, code)
src << ' @_erb_buf.concat(' << escaped_expr(code) << ');'
end
def add_stmt2(src, code, tailch)
#src << code << ';'
src << code
src << " ).to_s; " if tailch == "="
src << ';' unless code[-1] == ?\n
end
def add_expr_literal(src, code)
if code =~ /(do|\{)(\s*\|[^|]*\|)?\s*\Z/
src << ' @_erb_buf.concat( ' << code << "; "
else
src << ' @_erb_buf.concat((' << code << ').to_s);'
end
end
end
class BlockAwareEruby < Eruby
include BlockAwareEnhancer
end
end
class Context
def capture(&blk)
_old_buf, @_erb_buf = @_erb_buf, ""
blk.call
ret = @_erb_buf
@_erb_buf = _old_buf
ret
end
def hello
"Hello"
end
def hello2
"Hello"
end
def helper(&blk)
"<tag>#{capture(&blk)}</tag>"
end
end
# puts Erubis::BlockAwareEruby.new("Begin: <%= helper do %>Hello<% 3.times do %>X<% end %><% end %><%= hello %>").src
# p Erubis::BlockAwareEruby.new.process("Begin: <%= helper do %>Hello<%= 3.times do %>X<% end %><% end %><%= hello %>", Context.new)
def form_for(bar)
bar.to_s
end
class Foo
end
# _old_verbose, $VERBOSE = $VERBOSE, nil
# Erubis::BlockAwareEruby.new("<%= form_for :foo do %>Hello<% end %>").def_method(Foo, :stuffs)
# $VERBOSE = _old_verbose
# require "parse_tree"
require "ruby_parser"
require "ruby2ruby"
text = <<-END
Pre. <p><%= form_for :field do %>
Capturing
<% end =%>
<% if true %>Hello<% end %>
<% if false %>Goodbye<% end %>
END
p Erubis::BlockAwareEruby.new(text).src
p Erubis::BlockAwareEruby.new.process(text)
__END__
puts Erubis::BlockAwareEruby.new(<<-TEMPLATE).src
<ul id="nav">
<% @nav_items = [] %>
<% @nav_items << nav_item('Home', url(:root)) %>
<% @nav_items << nav_item('Messaging', url(:new_message)) if current_user.has_permission?('message.send') %>
<% if current_user.has_permission?('schedule.power_user') %>
<% @nav_items << "<li>\#{link_to('Schedule', 'https://belpark.net/schedule/pwrusr/', :popup => true)}</li>" %>
<% elsif current_user.has_permission?('schedule.view') %>
<% @nav_items << nav_item('Schedule', 'https://belpark.net/schedule/user/calendar.php') %>
<% end %>
<% if current_user.emails.exists?(["emails.address LIKE ?", '%@belpark.net']) %>
<% @nav_items << "<li>\#{link_to('Email', 'https://belpark.net/dwmail/', :popup => true)}</li>" %>
<% end %>
<% @nav_items << nav_item('Directory', url(:users)) if current_user.has_permission?('user.view') %>
<%= @nav_items.join('<li class="divider">|</li>') %>
</ul>
<ul id="nav2">
<% @nav_items = [] %>
<% @nav_items << "<li>\#{current_user.full_name}</li>" %>
<% @nav_items << "<li>\#{link_to('Settings', url(:edit_user, current_user.id))}</li>" if current_user.has_permission?('user.modify_self') %>
<% @nav_items << "<li>\#{link_to 'Log Out', url(:logout), :id => 'logout'}</li>" %>
<%= @nav_items.join('<li class="divider">|</li>') %>
</ul>
TEMPLATE
template = <<-HTML
<div>
<%= hello %>
<% [1,2,3,4,5,6,7,8,9,10].each do |i| %>
<%= i %>
<% end %>
</div>
<h3>Hello</h3>
<p>My name is testie McTesterson</p>
<div>
<%= hello %>
<% [1,2,3,4,5,6,7,8,9,10].each do |i| %>
<%= i %>
<% end %>
</div>
<h3>Hello</h3>
<p>My name is testie McTesterson</p>
<div>
<%= hello %>
<% [1,2,3,4,5,6,7,8,9,10].each do |i| %>
<%= i %>
<% end %>
</div>
<h3>Hello</h3>
<p>My name is testie McTesterson</p>
<div>
<%= hello %>
<% [1,2,3,4,5,6,7,8,9,10].each do |i| %>
<%= i %>
<% end %>
</div>
<h3>Hello</h3>
<p>My name is testie McTesterson</p>
<div>
<%= hello %>
<% [1,2,3,4,5,6,7,8,9,10].each do |i| %>
<%= i %>
<% end %>
</div>
<h3>Hello</h3>
<p>My name is testie McTesterson</p>
HTML
module Foo
end
require "benchmark"
require "rubygems"
require "erubis"
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("Compiling") do
TIMES.times { ::Erubis::Eruby.new(template).def_method(Foo, "template") }
end
end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("eval 1") { TIMES.times { eval "1" }}
x.report("eval :sym") { TIMES.times { eval ":sym" }}
x.report("1") { TIMES.times { 1 }}
x.report(":sym") { TIMES.times { :sym }}
end
# TIMES = 100_000
# user system total real
# eval 1 0.170000 0.000000 0.170000 ( 0.180040)
# eval :sym 0.180000 0.000000 0.180000 ( 0.181182)
# 1 0.010000 0.000000 0.010000 ( 0.010743)
# :sym 0.010000 0.000000 0.010000 ( 0.010676)
..........
Finished in 0.167371 seconds
10 examples, 0 failures
Total score = 8064.98074553779
Dispatcher#handle: (209.3)
60.0: assignment
41.6: branch
18.0: logger
13.2: []
12.3: params
10.6: raise
9.3: _session_id_key
9.2: join
8.9: inspect
8.2: info
7.5: map
6.4: new
5.0: cookies
4.9: route_params
4.7: message
4.4: _benchmarks
4.3: +
4.2: now
2.8: session
2.5: backtrace
2.4: _filter_params
2.3: routes
2.3: behavior
2.3: uri
2.2: to_s
2.2: warn!
2.2: snake_case
2.2: exception
2.2: controller_exception
2.2: dispatch_exception
2.2: _subclasses
2.1: allow_fixation?
2.1: dispatch_redirection
2.1: key?
2.1: redirects?
2.1: full_const_get
2.0: -
2.0: merge!
2.0: match
2.0: empty?
2.0: to_const_string
2.0: xhr?
2.0: dispatch_action
2.0: ==
2.0: include?
2.0: error
2.0: debug
2.0: flush
0.6: lit_fixnum
Config#parse_args: (177.6)
129.0: assignment
63.1: branch
52.5: on
7.1: puts
6.3: separator
4.7: exit
4.6: *
3.9: []
2.5: settings
2.4: require
2.4: start
2.4: respond_to?
2.2: expand_path
2.2: to_sym
2.2: ==
2.1: define_head
1.9: new
1.9: setup
1.9: parse!
1.3: lit_fixnum
Request#parse_multipart: (174.4)
65.6: assignment
60.1: branch
17.0: +
15.8: ==
14.8: size
12.4: slice!
11.6: empty?
9.4: binmode
7.5: []
7.2: <<
7.2: -
6.1: lit_fixnum
4.7: <
4.6: raise
4.4: read
4.4: index
2.7: new
2.6: nil?
2.5: path
2.3: rewind
2.3: >
2.3: basename
2.3: =~
2.1: normalize_params
1.9: loop
1.9: quote
Inflect#none: (118.3)
61.2: word
34.8: rule
7.2: alias_method
6.0: sclass
4.8: assignment
3.6: plural_rule
3.6: singular_rule
1.8: attr_reader
main#none: (113.3)
72.7: require
9.9: send
7.9: branch
7.3: dirname
5.0: []
3.4: assignment
2.7: /
2.4: include?
1.4: expand_path
1.3: testing?
1.3: exit
1.3: puts
1.2: unshift
1.1: desc
1.1: task
1.1: load
1.1: setup
1.1: join
1.0: each
MixinSessionContainer#run: (101.1)
21.6: /
13.5: []
11.3: logger
8.8: warn
7.2: include
6.9: framework_root
6.5: class_eval
6.2: branch
4.2: registered_session_types
3.9: register_session_type
3.7: check_for_secret_key
3.6: require
3.6: check_for_session_id_key
3.1: assignment
1.8: ==
1.5: to_s
1.5: include?
1.3: flush
Server#start: (99.4)
27.0: branch
16.0: assignment
11.5: puts
11.5: to_i
10.7: []
5.2: read
4.8: chomp
4.6: daemonize
4.6: remove_pid_file
4.5: exit
4.4: raise
4.2: alive?
4.2: exist?
4.2: pid_file
4.2: trap
2.3: +
2.3: to_hash
2.3: adapter
2.1: start
2.1: -
2.1: run
1.9: upto
0.6: lit_fixnum
Converter#convert_input: (94.7)
49.2: branch
33.3: assignment
16.8: add_text
9.0: ==
8.0: add_stmt
4.5: []
4.3: *
4.1: add_stmt2
3.9: respond_to?
3.4: empty?
2.3: lit_fixnum
2.0: count
1.8: +
1.7: add_expr
1.7: begin
1.6: detect_spaces_at_bol
1.5: -
1.5: end
1.5: last_match
1.4: pattern_regexp
1.4: nil?
1.3: scan
Behavior#resources: (89.1)
32.1: assignment
17.3: branch
8.1: match
6.5: to_s
5.3: delete
5.1: []
4.9: to_route
4.8: send
4.3: name
4.2: flatten
3.8: *
3.4: new
3.0: <<
3.0: merged_params
2.8: join
2.6: namespace_to_name_prefix
2.6: each_pair
2.6: nil?
1.5: map
1.4: yield
1.4: pop
1.4: push
1.4: +
1.2: ==
1.2: block_given?
1.2: many_behaviors_to
1.2: each
1.2: empty?
1.2: singularize
namespace#spec: (81.8)
38.3: assignment
36.8: []
16.9: branch
15.0: sort
7.2: new
6.0: desc
1.6: path
1.4: join
1.2: exist?
1.1: namespace
SessionMixin#finalize_session: (79.2)
16.1: request
14.5: session
12.7: branch
7.9: assignment
5.0: session_id
3.6: data
3.3: _session_cookie_domain
2.9: set_session_id_cookie
2.9: needs_new_cookie
2.7: ==
1.8: logger
1.8: message
1.8: finalize_session_exception_callbacks
1.8: _session_id_key
1.8: cookies
1.8: now
1.8: _session_expiry
1.7: call
1.7: dump
1.6: debug
1.6: each
1.6: +
1.6: set_cookie
1.5: set
1.5: hash
1.4: read_cookie
LoadClasses#load_classes_with_requirements: (75.5)
24.1: branch
22.9: assignment
13.9: size
8.8: ==
6.5: each
4.8: push
2.9: backtrace
2.6: join
2.6: class
2.6: logger
2.6: message
2.5: only
2.5: inspect
2.4: fatal!
2.4: load_file
2.3: raise
2.3: delete
2.2: include?
2.0: >
1.9: uniq!
Route#generate: (73.0)
30.1: branch
14.5: assignment
8.0: []
8.0: respond_to?
6.9: is_a?
6.6: send
5.6: ==
4.5: +
4.2: to_param
3.4: delete
3.3: raise
2.1: class
1.9: to_s
1.8: params_to_query_string
1.7: unescape_regexp
1.5: map
1.4: empty?
1.4: dup
1.3: join
1.3: regexp?
Behavior#compiled_params: (72.8)
23.2: assignment
15.8: branch
15.7: []
11.0: <<
8.0: pre_match
5.2: empty?
3.5: post_match
3.4: raise
3.1: match
2.7: lit_fixnum
1.7: intern
1.7: inspect
1.7: to_s
1.6: array_to_code
1.4: gsub
1.4: is_a?
1.4: dup
1.2: merged_placeholders
1.2: merged_params
1.2: each_pair
main#run_specs: (70.8)
39.9: assignment
14.8: branch
8.1: +
7.3: puts
6.9: to_i
4.6: is_a?
3.8: print
3.7: []
2.7: each
2.4: require
2.3: match
2.0: read
1.9: flush
1.8: gets
1.7: expand_path
1.6: real
1.5: popen3
1.4: sprintf
1.2: ==
1.2: measure
0.5: lit_fixnum
Dispatcher#dispatch_exception: (68.7)
22.4: assignment
18.2: branch
14.8: params
6.7: dispatch_default_exception
6.5: class
6.3: is_a?
6.3: dup
4.2: name
2.3: cookies
2.3: session
2.3: []
2.3: superclass
2.2: status
2.1: ==
2.0: controller_exception
2.0: dispatch_action
LoadClasses#remove_constant: (67.6)
20.7: send
9.8: assignment
7.7: branch
6.4: to_s
5.0: klass
4.5: logger
4.5: []
4.4: delete
4.1: debug
2.2: superclass
2.2: join
2.1: size
2.0: full_const_get
2.0: respond_to?
2.0: nil?
1.9: ==
1.9: split
0.5: lit_fixnum
RenderMixin#render: (67.3)
18.7: assignment
11.7: branch
8.7: send
8.4: +
6.8: []
5.5: content_type
5.0: join
4.4: template_extensions
3.8: is_a?
2.8: throw_content
1.6: raise
1.6: map
1.6: controller_name
1.6: class
1.5: respond_to?
1.4: _template_for
1.4: default_render_options
1.4: action_name
1.3: catch_content
1.2: _get_layout
1.2: merge
1.2: to_sym
1.2: _handle_options!
Merb#none: (67.0)
24.0: autoload
17.0: sclass
8.9: attr_accessor
7.2: alias
5.9: branch
3.7: assignment
2.0: load_paths
2.0: root
1.9: new
1.8: attr_reader
1.8: is_a?
Router#generate_for_default_route: (63.7)
26.1: assignment
25.6: branch
22.9: []
10.4: +
4.2: raise
4.1: empty?
2.4: params_to_query_string
2.2: to_sym
2.1: ==
2.0: include?
1.9: reject
RenderMixin#display: (63.2)
23.4: assignment
16.2: branch
14.7: send
5.3: content_type
3.5: message
3.1: raise
3.0: merge
2.8: delete
1.9: to_s
1.9: action_name
1.8: class
1.7: inspect
1.7: index
1.7: to_sym
1.6: empty?
1.6: default_render_options
1.5: catch_content
1.5: _template_for
1.5: respond_to?
1.4: throw_content
1.4: _handle_options!
1.4: render
1.4: mime_transform_method
BootLoader#run: (60.3)
19.3: branch
9.4: []
9.2: logger
8.0: assignment
6.6: subclasses
5.1: now
4.7: to_i
4.4: debug!
2.4: -
2.3: full_const_get
2.3: finished
2.1: shift
2.1: <<
2.1: run
2.0: empty?
1.9: dup
Route#if_conditions: (60.1)
21.3: assignment
17.6: branch
6.8: +
5.3: []
4.6: to_a
4.5: <<
4.2: map
3.8: join
3.6: inspect
3.6: source
1.9: scan
1.8: new
1.7: flatten
1.7: size
1.5: first
1.5: empty?
1.5: count_parens_up_to
1.5: ==
1.3: each_pair
1.3: proc
1.3: lit_fixnum
BootLoader#default_framework: (53.6)
19.1: push_path
10.6: root_path
9.0: dir_for
6.3: /
4.0: branch
2.2: []
2.2: to_sym
2.1: log_path
2.0: assignment
1.9: each
Console#show_routes: (53.6)
17.3: puts
10.9: branch
10.9: assignment
4.0: conditions
4.0: params
3.6: inspect
3.6: []
3.4: upcase
3.2: to_s
3.2: named_routes
2.8: each
1.7: <<
1.7: routes
1.5: -
1.3: empty?
ResponderMixin#_perform_content_negotiation: (53.0)
14.9: assignment
11.8: branch
4.8: first
4.2: +
4.2: request
3.8: accept
3.6: join
3.4: to_sym
3.4: _provided_formats
3.0: empty?
3.0: ==
2.0: parse
1.8: map
1.7: params
1.6: %
1.6: compact
1.6: length
1.5: include?
1.5: []
1.4: raise
1.4: &
BuildFramework#build_framework: (51.8)
12.9: /
9.7: branch
9.6: root
7.7: assignment
4.4: []
3.9: require
3.7: exists?
2.4: length
2.2: first
2.2: ==
2.0: push_path
2.0: Array
2.0: default_framework
1.8: each
1.2: lit_fixnum
RenderMixin#partial: (50.8)
23.3: assignment
11.4: branch
5.4: send
4.2: delete
3.1: to_sym
2.9: basename
2.9: match
2.8: []
1.7: raise
1.7: respond_to?
1.5: controller_name
1.5: dirname
1.5: content_type
1.4: map
1.4: size
1.3: /
1.2: pop
1.2: join
1.2: _template_for
1.2: flatten
1.2: key?
1.2: to_s
1.2: merge
1.2: push
0.8: lit_fixnum
Route#compile: (49.2)
9.7: []
9.6: <<
9.5: assignment
8.2: branch
7.4: params
6.3: inspect
3.0: join
1.9: if_conditions
1.7: keys
1.7: merged_original_conditions
1.5: ==
1.5: map
1.5: has_key?
1.3: proc
0.4: lit_fixnum
Templates#template_paths: (48.8)
15.9: assignment
9.6: branch
4.1: dir_for
4.0: map
4.0: uniq
4.0: []
4.0: compact
2.4: _template_roots
2.4: full_const_get
2.3: first
2.2: _template_root
2.2: flatten
2.0: +
2.0: template_extensions
2.0: blank?
2.0: _abstract_subclasses
1.9: <<
1.8: each
1.8: join
LoadClasses#run: (48.7)
12.7: dir_for
8.0: branch
7.6: unshift
6.0: assignment
5.7: send
4.7: last
2.5: first
2.3: /
2.2: ==
2.1: load_classes
2.1: load_paths
2.0: load_file
1.9: each
1.9: file?
SessionMixin#setup_session: (46.4)
17.6: assignment
8.0: request
4.9: _session_id_key
4.9: cookies
4.3: []
3.5: session
2.9: set_session_id_cookie
2.7: ==
2.7: persist
2.7: branch
1.7: data
1.6: _session_secret_key
1.5: dump
1.4: new
1.4: read_cookie
1.3: hash
Behavior#resource: (43.6)
9.8: assignment
7.6: match
7.2: branch
5.6: to_route
4.8: name
3.9: []
3.0: merged_params
2.6: namespace_to_name_prefix
2.6: nil?
1.5: join
1.4: push
1.4: pop
1.4: yield
1.3: to_s
1.2: delete
1.2: block_given?
1.2: empty?
1.2: to_resource
Mongrel#process: (42.4)
18.6: assignment
11.2: branch
4.4: each
4.0: delete
3.4: body
3.0: []
2.8: call
2.6: ==
1.6: <<
1.6: header
1.6: new
1.5: params
1.4: to_i
1.4: close
1.4: ===
1.4: finished
1.3: update
1.3: replace
1.3: respond_to?
0.4: lit_fixnum
Server#daemonize: (41.6)
9.6: branch
6.0: reopen
4.2: exit
4.0: []
3.8: fork
2.2: to_hash
2.2: adapter
2.1: remove_pid_file
2.0: at_exit
2.0: setsid
2.0: umask
2.0: trap
2.0: start
2.0: chdir
2.0: run
2.0: assignment
1.9: puts
Const#none: (41.5)
35.6: freeze
3.3: *
1.3: lit_fixnum
1.3: at
Merb#merge_env: (40.6)
8.9: environment_info
8.0: assignment
7.8: branch
4.4: []
4.4: /
4.0: environment
2.5: dir_for
2.4: logger
2.2: load
2.2: warn!
2.1: exists?
2.1: <<
1.9: member?
1.9: nil?
Dispatcher#dispatch_default_exception: (40.0)
8.3: assignment
6.0: send
4.2: branch
4.0: instance_variable_set
2.8: name
2.6: split
2.5: capitalize
2.4: map
2.2: class
2.2: message
2.2: template_for
2.2: join
2.2: headers
2.0: status
2.0: merge!
1.8: is_a?
1.8: new
Server#kill: (38.7)
9.0: puts
8.2: branch
7.8: assignment
4.7: rm
2.5: read
2.3: kill
2.3: exist?
2.3: chomp
2.1: to_i
2.0: pid_file
2.0: pid_files
1.9: ==
1.9: each
1.8: run
1.8: exit
0.5: lit_fixnum
Thin#start: (37.8)
20.0: []
10.7: assignment
6.6: branch
3.2: logger
2.8: warn!
2.8: start
1.6: to_i
1.5: root
1.4: include?
1.2: change_privilege
1.2: start!
MemCacheSession#persist: (37.8)
15.2: assignment
10.3: branch
4.3: new
4.1: session_id
2.5: persist_exception_callbacks
2.5: logger
2.5: message
2.4: call
2.3: warn!
2.3: each
2.2: get
2.1: nil?
2.0: generate
1.9: is_a?
1.9: blank?
RackUpApplication#run: (35.4)
7.0: eval
6.1: []
5.8: assignment
5.6: branch
5.0: dir_for
3.5: use
3.4: new
2.7: /
1.7: run
1.4: read
1.3: to_app
1.2: require
1.2: exists?
RenderMixin#_template_for: (35.0)
17.4: assignment
10.8: branch
10.8: send
4.7: /
2.9: is_a?
2.8: _template_method_for
1.6: index
1.6: class
1.4: _absolute_template_location
1.4: _template_roots
1.2: reverse_each
Template#template_for: (34.9)
12.0: assignment
6.5: []
6.1: branch
5.4: template_extensions
5.0: join
4.8: load_template_io
4.4: inline_template
4.2: first
1.9: expand_path
Server#pid_file: (34.2)
15.1: []
10.6: assignment
4.4: log_path
4.0: /
3.8: branch
2.2: extname
2.2: join
2.2: basename
2.2: dirname
Router#generate: (33.9)
18.6: assignment
9.8: branch
4.3: nil?
4.1: reject!
3.8: is_a?
2.3: merge
2.2: []
2.1: generate_for_default_route
2.0: generate
2.0: raise
1.9: to_sym
1.9: key?
AbstractController#_dispatch: (33.2)
11.6: assignment
11.5: branch
5.8: now
3.0: _before_filters
2.8: -
2.6: _after_filters
2.6: _call_filters
1.6: action_name
1.4: call
1.4: __send__
1.4: _call_action
1.4: _filters_halted
1.3: raise
1.2: finalize_session
1.2: catch
1.2: setup_session
Request#none: (32.3)
7.2: freeze
6.5: class_eval
6.1: assignment
6.0: sclass
4.8: alias
2.4: cattr_accessor
1.2: private
1.2: each
1.2: public
1.2: branch
1.2: attr_accessor
Logger#initialize_log: (32.3)
8.3: assignment
6.0: branch
5.9: |
3.9: dirname
3.8: delimiter
3.4: open
2.1: now
1.9: httpdate
1.8: mkdir_p
1.7: write
1.7: directory?
1.5: close
1.5: exist?
1.4: respond_to?
RequestHelper#request: (31.9)
14.3: assignment
6.1: delete
2.9: +
2.8: block_pass
2.8: branch
1.7: snake_case
1.5: to_const_string
1.5: []
1.4: dispatch_multipart_to
1.4: dispatch_to
1.3: full_const_get
1.3: to_s
1.3: merge!
1.3: nil?
1.3: fake_request
1.3: split
1.3: check_request_for_route
AbstractController#_call_filters: (31.7)
11.2: branch
10.5: send
8.0: instance_eval
5.7: assignment
1.8: []
1.6: block_pass
1.6: key?
1.6: action_name
1.4: _call_filter_for_action?
1.4: _filter_condition_met?
1.2: each
Server#change_privilege: (31.6)
22.0: []
7.9: branch
4.4: puts
4.2: _change_privilege
Post#push_params: (31.0)
10.7: branch
10.4: assignment
3.7: new
3.4: is_a?
3.3: <<
3.0: each
2.0: read
2.0: path
1.9: keys
1.8: push_params
1.6: to_s
1.5: respond_to?
1.5: nil?
1.5: sort_by
Server#_change_privilege: (31.0)
13.7: assignment
5.8: branch
4.4: change_privilege
4.2: ==
4.0: puts
2.2: getgrnam
2.2: initgroups
2.2: getpwnam
2.0: uid
2.0: egid
2.0: euid
2.0: gid
AbstractController#add_filter: (30.6)
12.6: branch
6.6: assignment
5.3: raise
5.2: key?
3.4: to_s
1.9: first
1.7: last
1.5: <<
1.5: []
1.5: replace
1.4: find
1.3: include?
1.2: normalize_filters!
1.2: each_key
Server#pid_files: (30.5)
16.6: []
6.3: assignment
4.4: /
3.7: branch
2.3: log_path
2.1: extname
2.1: basename
2.1: dirname
ReloadClasses#reload: (30.3)
11.4: assignment
9.7: branch
5.1: []
4.6: dir_for
2.9: <<
2.6: each
1.9: /
1.8: mtime
1.6: ==
1.5: reload
1.5: flatten
1.5: load_paths
1.4: file?
Application#call: (30.3)
5.5: assignment
3.0: +
2.8: logger
2.0: pwd
1.8: backtrace
1.8: /
1.8: message
1.6: open
1.6: join
1.4: print
1.4: stop
1.4: new
1.4: start
1.4: handle
1.2: flush
1.2: info
1.2: status
1.2: headers
1.2: body
1.2: branch
0.4: lit_fixnum
RenderMixin#_get_layout: (30.2)
16.6: assignment
10.4: branch
5.0: content_type
4.3: _template_for
3.9: send
1.6: index
1.6: controller_name
1.5: raise
1.3: respond_to?
1.3: instance_of?
1.3: to_s
1.2: ==
Rack#none: (30.2)
19.2: autoload
11.0: register
Kernel#__caller_lines__: (29.8)
16.1: assignment
6.0: +
4.8: branch
2.7: size
2.4: -
1.6: ==
1.6: chomp
1.6: lit_fixnum
1.4: <<
1.4: to_i
1.2: >
1.2: <
1.2: readlines
1.2: []
1.2: each_with_index
Request#params: (29.6)
8.4: branch
5.1: class
4.5: merge!
3.2: multipart_params
3.2: xml_params
3.2: json_params
2.7: assignment
1.6: body_and_query_params
1.6: route_params
1.5: parse_multipart_params
1.5: parse_xml_params
1.5: parse_json_params
1.4: merge
Merb#start: (29.6)
14.7: []
7.8: branch
5.7: assignment
4.2: kill
2.0: setup
2.0: start
2.0: parse_args
1.9: ===
1.2: lit_fixnum
Route#segments_from_path: (28.8)
6.9: assignment
6.8: []
5.4: branch
4.5: <<
3.7: pre_match
3.0: gsub
2.8: empty?
1.7: post_match
1.7: intern
1.4: match
1.3: proc
0.5: lit_fixnum
Controller#none: (28.5)
6.6: include
5.5: sclass
5.5: assignment
3.5: []
2.8: private
2.2: branch
1.3: _callable_methods
1.2: *
1.1: attr_reader
1.1: hide_action
1.1: new
1.1: attr_accessor
1.1: class_inheritable_accessor
1.1: cattr_accessor
0.4: lit_fixnum
Controller#_callable_methods: (28.2)
7.5: assignment
5.5: branch
5.2: public_instance_methods
4.0: ==
2.6: _shown_actions
2.4: +
2.4: _hidden_actions
2.2: -
2.0: <<
2.0: flatten
2.0: superclass
1.8: reject
LoadClasses#remove_classes_in_file: (28.0)
11.7: branch
8.0: assignment
5.8: each
4.2: klass_hashes
2.2: remove_constant
2.1: to_s
2.0: unprotect_keys!
2.0: yield
2.0: protect_keys!
1.9: block_given?
1.9: delete
Request#params_to_query_string: (27.3)
13.1: branch
11.5: assignment
7.4: escape
4.8: params_to_query_string
4.6: map
4.2: *
Dictionary#[]: (26.9)
5.7: branch
5.3: []
4.2: shift
3.9: assignment
2.3: size
2.1: empty?
2.1: %
2.0: raise
1.9: replace
1.9: ==
1.8: new
1.8: ===
0.6: lit_fixnum
Runner#start: (26.2)
14.0: eval
6.0: []
2.4: branch
1.6: read
1.3: exit
1.3: exists?
1.1: change_privilege
1.1: assignment
0.8: lit_fixnum
Request#query_parse: (26.0)
18.0: assignment
8.0: branch
4.2: split
3.8: inject
2.3: unescape
2.1: normalize_params
2.0: to_mash
2.0: new
0.6: lit_fixnum
Inflect#clear: (25.4)
22.9: assignment
8.0: ==
7.6: branch
Irb#start: (25.4)
6.6: branch
4.0: assignment
3.9: send
2.7: sandboxed?
2.6: extend
2.6: require
1.7: merb
1.5: close_sandbox!
1.4: open_sandbox!
1.3: at_exit
1.3: exit
1.3: start
1.3: new
1.3: exists?
1.3: clear
AcceptType#to_sym: (25.3)
9.0: []
5.7: assignment
4.6: synonyms
4.0: ==
3.7: branch
2.0: available_mime_types
1.8: select
1.6: flatten
1.4: first
Request#method: (25.1)
11.4: branch
8.1: assignment
3.5: []
3.2: to_sym
2.1: class
1.9: call
1.9: http_method_overrides
1.8: downcase!
1.7: include?
1.7: each
1.6: downcase
1.5: raise
Merb#add_mime_type: (25.1)
8.7: assignment
8.5: class_eval
5.1: branch
3.5: update
1.8: +
1.8: []
1.8: first
1.7: delete
1.7: enforce!
1.7: each
0.5: lit_fixnum
Logger#none: (24.9)
7.0: class_eval
4.2: assignment
3.9: attr_reader
3.9: attr_accessor
2.6: alias
2.6: branch
1.8: lit_fixnum
1.3: each_pair
1.3: public
1.3: const_defined?
1.3: private
Server#alive?: (24.5)
7.8: branch
6.3: puts
6.0: []
4.0: assignment
2.4: read
2.2: chomp
2.0: pid_file
2.0: to_i
2.0: kill
ControllerMixin#stream_file: (23.6)
7.5: []
3.7: assignment
2.4: update
2.4: branch
1.4: send_header
1.4: call
1.4: send_status
1.4: strip
1.4: headers
1.4: merge
1.3: dup
1.2: <<
1.2: new
1.2: must_support_streaming!
ResponderMixin#content_type=: (23.2)
8.7: assignment
7.5: []
4.2: branch
3.2: available_mime_types
2.9: headers
1.7: new
1.5: raise
1.5: call
1.4: has_key?
1.4: each
Behavior#deduce_placeholders: (23.2)
10.4: assignment
7.2: []
4.0: branch
2.1: offset
2.1: lit_fixnum
1.7: count_parens_up_to
1.7: intern
1.5: sub!
1.5: ==
1.4: match
1.2: each_pair
Merb#log_file: (23.2)
10.7: []
8.1: branch
4.7: log_path
4.3: /
2.0: testing?
Router#compiled_statement: (23.0)
12.7: <<
6.6: assignment
4.0: branch
2.6: ==
2.4: compile
2.1: each_with_index
1.9: synchronize
Request#normalize_params: (22.9)
10.0: assignment
9.8: branch
5.0: []
4.8: normalize_params
4.4: <<
3.9: ==
Inflect#plural: (22.8)
13.4: assignment
5.7: branch
4.0: plural_of
3.9: []
3.9: dup
1.9: sub!
1.9: pluralization_rules
1.9: ==
HasTag#matches?: (22.6)
8.3: branch
4.4: assignment
3.8: selector
3.4: search
2.9: parse
2.8: empty?
2.6: nil?
1.8: call
1.7: string
1.6: select
Request#escape: (22.6)
3.2: size
3.0: *
2.8: unpack
2.6: join
2.4: upcase
2.3: to_s
2.2: +
2.1: gsub
2.1: branch
1.9: tr
Inflect#singularization_rules: (22.5)
12.2: assignment
6.5: branch
4.4: +
2.7: map
2.5: join
2.3: flatten
2.1: []
1.9: new
1.9: invert
Route#behavior_trace: (22.5)
6.9: send
5.9: puts
3.7: inspect
3.2: branch
2.1: reverse
2.0: assignment
1.9: map
1.7: join
AbstractController#none: (22.4)
5.5: sclass
4.4: attr_accessor
4.4: include
4.4: assignment
2.2: alias_method
2.2: class_inheritable_accessor
1.1: private
1.1: new
1.1: cattr_accessor
BootLoader#move_klass: (22.0)
6.7: to_s
6.7: subclasses
2.3: +
2.1: insert
2.1: delete
1.9: assignment
1.9: index
1.9: branch
Server#store_pid: (21.9)
5.4: branch
4.1: dirname
3.7: puts
3.7: assignment
2.1: pid
1.9: mkdir_p
1.9: write
1.8: []
1.8: directory?
1.8: pid_file
1.8: open
Behavior#array_to_code: (21.2)
10.0: branch
7.5: assignment
6.5: <<
2.4: to_s
2.3: class
2.1: raise
2.0: >
1.8: each_with_index
Behavior#concat_without_endcaps: (21.1)
10.8: branch
7.8: []
3.6: nil?
3.6: assignment
3.6: ==
1.8: +
1.0: lit_fixnum
Inflect#singular: (20.9)
13.4: assignment
4.0: singular_of
3.9: dup
3.9: []
3.8: branch
1.9: sub!
1.9: singularization_rules
Inflect#pluralization_rules: (20.8)
12.2: assignment
6.5: branch
4.4: +
2.7: map
2.5: join
2.1: flatten
1.9: []
1.9: new
Logger#set_log: (20.7)
14.5: assignment
6.2: []
4.3: branch
3.4: to_sym
1.7: environment
1.5: ==
1.4: initialize_log
Static#call: (19.3)
9.0: branch
5.4: []
3.9: assignment
2.8: serve_static
2.7: file_exist?
1.5: call
1.4: empty?
1.3: chomp
1.2: +
0.4: lit_fixnum
Behavior#merged_placeholders: (19.2)
12.7: assignment
4.2: branch
2.9: +
1.8: total_previous_captures
1.8: ancestors
1.7: ==
1.6: reverse
1.5: placeholders
1.3: each_pair
1.2: each
Router#compile: (19.0)
9.5: eval
4.3: compiled_statement
2.1: binding
2.0: puts
1.9: branch
1.1: lit_fixnum
RouteToMatcher#matches?: (18.9)
6.6: assignment
4.4: delete
4.0: branch
3.2: snake_case
2.9: ==
2.6: to_s
1.5: match_parameters
1.3: has_key?
1.3: dup
Router#capture: (18.8)
5.7: assignment
4.2: routes
4.2: named_routes
1.9: yield
1.9: dup
1.9: except
1.9: -
1.9: keys
Request#path: (18.8)
4.1: branch
3.7: uri
3.0: []
2.7: assignment
1.8: split
1.6: size
1.6: first
1.5: empty?
1.4: >
1.4: ==
1.3: squeeze
0.8: lit_fixnum
Post#to_multipart: (18.6)
11.7: +
3.5: assignment
2.4: to_multipart
2.1: branch
2.1: collect
1.9: join
ControllerMixin#send_file: (18.1)
6.0: []
2.6: branch
2.4: assignment
2.4: update
1.5: basename
1.4: merge
1.4: strip
1.4: headers
1.3: dup
1.2: <<
1.2: open
Dispatcher#none: (18.0)
5.5: sclass
3.4: new
1.7: []
1.7: assignment
1.7: attr_accessor
1.7: private
1.5: dirname
1.3: /
1.1: expand_path
LoadClasses#load_classes: (17.8)
8.3: assignment
6.0: branch
3.9: each
2.3: unshift
2.2: load_file
2.2: []
2.1: flatten
1.9: load_classes_with_requirements
AbstractController#inherited: (17.6)
8.5: class_eval
3.6: to_s
1.9: _abstract_subclasses
1.7: <<
1.7: make_module
1.7: branch
1.7: assignment
Dispatcher#dispatch_redirection: (17.5)
9.0: assignment
4.0: behavior
2.0: logger
1.8: info
1.8: redirect_url
1.8: new
1.8: redirect_status
1.8: headers
Responder#parse: (17.4)
8.7: assignment
2.8: branch
2.0: []
1.8: new
1.7: size
1.6: <<
1.6: +
1.5: <
1.4: ==
1.4: sort
1.4: split
0.5: lit_fixnum
Cookies#set_cookie: (17.2)
10.1: assignment
4.4: branch
2.4: []
2.0: map
1.8: sort
1.6: join
1.5: gmtime
1.4: +
1.3: strftime
1.2: <<
SwiftipliedMongrel#start: (16.6)
4.6: []
3.6: assignment
2.6: new
1.4: to_i
1.4: logger
1.4: run
1.2: join
1.2: warn!
1.2: register
1.2: change_privilege
EventedMongrel#start: (16.6)
4.6: []
3.6: assignment
2.6: new
1.4: to_i
1.4: logger
1.4: run
1.2: join
1.2: warn!
1.2: register
1.2: change_privilege
Request#remote_ip: (16.6)
5.6: branch
4.6: []
3.1: assignment
2.6: include?
1.8: first
1.7: split
1.6: strip
1.5: empty?
1.5: reject
AbstractController#normalize_filters!: (16.4)
6.6: assignment
5.8: []
5.0: branch
3.0: Array
2.8: to_s
2.6: map
Kernel#__profile__: (16.4)
9.9: assignment
4.9: branch
1.4: yield
1.4: root
1.3: print
1.3: require
1.3: times
1.2: new
1.2: profile
1.2: open
1.2: join
0.6: lit_fixnum
RenderMixin#throw_content: (16.4)
5.0: branch
3.0: []
2.7: block_given?
2.6: <<
2.5: assignment
1.6: to_s
1.5: capture
1.5: block_pass
1.3: raise
1.2: nil?
Total score = 8051.13102792593
Dispatcher#handle: (209.3)
60.0: assignment
41.6: branch
18.0: logger
13.2: []
12.3: params
10.6: raise
9.3: _session_id_key
9.2: join
8.9: inspect
8.2: info
7.5: map
6.4: new
5.0: cookies
4.9: route_params
4.7: message
4.4: _benchmarks
4.3: +
4.2: now
2.8: session
2.5: backtrace
2.4: _filter_params
2.3: routes
2.3: behavior
2.3: uri
2.2: to_s
2.2: warn!
2.2: snake_case
2.2: exception
2.2: controller_exception
2.2: dispatch_exception
2.2: _subclasses
2.1: allow_fixation?
2.1: dispatch_redirection
2.1: key?
2.1: redirects?
2.1: full_const_get
2.0: -
2.0: merge!
2.0: match
2.0: empty?
2.0: to_const_string
2.0: xhr?
2.0: dispatch_action
2.0: ==
2.0: include?
2.0: error
2.0: debug
2.0: flush
0.6: lit_fixnum
Config#parse_args: (177.6)
129.0: assignment
63.1: branch
52.5: on
7.1: puts
6.3: separator
4.7: exit
4.6: *
3.9: []
2.5: settings
2.4: require
2.4: start
2.4: respond_to?
2.2: expand_path
2.2: to_sym
2.2: ==
2.1: define_head
1.9: new
1.9: setup
1.9: parse!
1.3: lit_fixnum
Request#parse_multipart: (174.4)
65.6: assignment
60.1: branch
17.0: +
15.8: ==
14.8: size
12.4: slice!
11.6: empty?
9.4: binmode
7.5: []
7.2: <<
7.2: -
6.1: lit_fixnum
4.7: <
4.6: raise
4.4: read
4.4: index
2.7: new
2.6: nil?
2.5: path
2.3: rewind
2.3: >
2.3: basename
2.3: =~
2.1: normalize_params
1.9: loop
1.9: quote
Inflect#none: (118.3)
61.2: word
34.8: rule
7.2: alias_method
6.0: sclass
4.8: assignment
3.6: plural_rule
3.6: singular_rule
1.8: attr_reader
main#none: (112.2)
71.6: require
9.9: send
7.9: branch
7.3: dirname
5.0: []
3.4: assignment
2.7: /
2.4: include?
1.4: expand_path
1.3: testing?
1.3: exit
1.3: puts
1.2: unshift
1.1: desc
1.1: task
1.1: load
1.1: setup
1.1: join
1.0: each
MixinSessionContainer#run: (101.1)
21.6: /
13.5: []
11.3: logger
8.8: warn
7.2: include
6.9: framework_root
6.5: class_eval
6.2: branch
4.2: registered_session_types
3.9: register_session_type
3.7: check_for_secret_key
3.6: require
3.6: check_for_session_id_key
3.1: assignment
1.8: ==
1.5: to_s
1.5: include?
1.3: flush
Server#start: (99.4)
27.0: branch
16.0: assignment
11.5: puts
11.5: to_i
10.7: []
5.2: read
4.8: chomp
4.6: daemonize
4.6: remove_pid_file
4.5: exit
4.4: raise
4.2: alive?
4.2: exist?
4.2: pid_file
4.2: trap
2.3: +
2.3: to_hash
2.3: adapter
2.1: start
2.1: -
2.1: run
1.9: upto
0.6: lit_fixnum
Converter#convert_input: (94.7)
49.2: branch
33.3: assignment
16.8: add_text
9.0: ==
8.0: add_stmt
4.5: []
4.3: *
4.1: add_stmt2
3.9: respond_to?
3.4: empty?
2.3: lit_fixnum
2.0: count
1.8: +
1.7: add_expr
1.7: begin
1.6: detect_spaces_at_bol
1.5: -
1.5: end
1.5: last_match
1.4: pattern_regexp
1.4: nil?
1.3: scan
Behavior#resources: (89.1)
32.1: assignment
17.3: branch
8.1: match
6.5: to_s
5.3: delete
5.1: []
4.9: to_route
4.8: send
4.3: name
4.2: flatten
3.8: *
3.4: new
3.0: <<
3.0: merged_params
2.8: join
2.6: namespace_to_name_prefix
2.6: each_pair
2.6: nil?
1.5: map
1.4: yield
1.4: pop
1.4: push
1.4: +
1.2: ==
1.2: block_given?
1.2: many_behaviors_to
1.2: each
1.2: empty?
1.2: singularize
namespace#spec: (81.8)
38.3: assignment
36.8: []
16.9: branch
15.0: sort
7.2: new
6.0: desc
1.6: path
1.4: join
1.2: exist?
1.1: namespace
SessionMixin#finalize_session: (79.2)
16.1: request
14.5: session
12.7: branch
7.9: assignment
5.0: session_id
3.6: data
3.3: _session_cookie_domain
2.9: set_session_id_cookie
2.9: needs_new_cookie
2.7: ==
1.8: logger
1.8: message
1.8: finalize_session_exception_callbacks
1.8: _session_id_key
1.8: cookies
1.8: now
1.8: _session_expiry
1.7: call
1.7: dump
1.6: debug
1.6: each
1.6: +
1.6: set_cookie
1.5: set
1.5: hash
1.4: read_cookie
LoadClasses#load_classes_with_requirements: (75.5)
24.1: branch
22.9: assignment
13.9: size
8.8: ==
6.5: each
4.8: push
2.9: backtrace
2.6: join
2.6: class
2.6: logger
2.6: message
2.5: only
2.5: inspect
2.4: fatal!
2.4: load_file
2.3: raise
2.3: delete
2.2: include?
2.0: >
1.9: uniq!
Route#generate: (73.0)
30.1: branch
14.5: assignment
8.0: []
8.0: respond_to?
6.9: is_a?
6.6: send
5.6: ==
4.5: +
4.2: to_param
3.4: delete
3.3: raise
2.1: class
1.9: to_s
1.8: params_to_query_string
1.7: unescape_regexp
1.5: map
1.4: empty?
1.4: dup
1.3: join
1.3: regexp?
Behavior#compiled_params: (72.8)
23.2: assignment
15.8: branch
15.7: []
11.0: <<
8.0: pre_match
5.2: empty?
3.5: post_match
3.4: raise
3.1: match
2.7: lit_fixnum
1.7: intern
1.7: inspect
1.7: to_s
1.6: array_to_code
1.4: gsub
1.4: is_a?
1.4: dup
1.2: merged_placeholders
1.2: merged_params
1.2: each_pair
main#run_specs: (70.8)
39.9: assignment
14.8: branch
8.1: +
7.3: puts
6.9: to_i
4.6: is_a?
3.8: print
3.7: []
2.7: each
2.4: require
2.3: match
2.0: read
1.9: flush
1.8: gets
1.7: expand_path
1.6: real
1.5: popen3
1.4: sprintf
1.2: ==
1.2: measure
0.5: lit_fixnum
Dispatcher#dispatch_exception: (68.7)
22.4: assignment
18.2: branch
14.8: params
6.7: dispatch_default_exception
6.5: class
6.3: is_a?
6.3: dup
4.2: name
2.3: cookies
2.3: session
2.3: []
2.3: superclass
2.2: status
2.1: ==
2.0: controller_exception
2.0: dispatch_action
LoadClasses#remove_constant: (67.6)
20.7: send
9.8: assignment
7.7: branch
6.4: to_s
5.0: klass
4.5: logger
4.5: []
4.4: delete
4.1: debug
2.2: superclass
2.2: join
2.1: size
2.0: full_const_get
2.0: respond_to?
2.0: nil?
1.9: ==
1.9: split
0.5: lit_fixnum
RenderMixin#render: (67.3)
18.7: assignment
11.7: branch
8.7: send
8.4: +
6.8: []
5.5: content_type
5.0: join
4.4: template_extensions
3.8: is_a?
2.8: throw_content
1.6: raise
1.6: map
1.6: controller_name
1.6: class
1.5: respond_to?
1.4: _template_for
1.4: default_render_options
1.4: action_name
1.3: catch_content
1.2: _get_layout
1.2: merge
1.2: to_sym
1.2: _handle_options!
Merb#none: (67.0)
24.0: autoload
17.0: sclass
8.9: attr_accessor
7.2: alias
5.9: branch
3.7: assignment
2.0: load_paths
2.0: root
1.9: new
1.8: attr_reader
1.8: is_a?
Router#generate_for_default_route: (63.7)
26.1: assignment
25.6: branch
22.9: []
10.4: +
4.2: raise
4.1: empty?
2.4: params_to_query_string
2.2: to_sym
2.1: ==
2.0: include?
1.9: reject
RenderMixin#display: (63.2)
23.4: assignment
16.2: branch
14.7: send
5.3: content_type
3.5: message
3.1: raise
3.0: merge
2.8: delete
1.9: to_s
1.9: action_name
1.8: class
1.7: inspect
1.7: index
1.7: to_sym
1.6: empty?
1.6: default_render_options
1.5: catch_content
1.5: _template_for
1.5: respond_to?
1.4: throw_content
1.4: _handle_options!
1.4: render
1.4: mime_transform_method
BootLoader#run: (60.3)
19.3: branch
9.4: []
9.2: logger
8.0: assignment
6.6: subclasses
5.1: now
4.7: to_i
4.4: debug!
2.4: -
2.3: full_const_get
2.3: finished
2.1: shift
2.1: <<
2.1: run
2.0: empty?
1.9: dup
Route#if_conditions: (60.1)
21.3: assignment
17.6: branch
6.8: +
5.3: []
4.6: to_a
4.5: <<
4.2: map
3.8: join
3.6: inspect
3.6: source
1.9: scan
1.8: new
1.7: flatten
1.7: size
1.5: first
1.5: empty?
1.5: count_parens_up_to
1.5: ==
1.3: each_pair
1.3: proc
1.3: lit_fixnum
BootLoader#default_framework: (53.6)
19.1: push_path
10.6: root_path
9.0: dir_for
6.3: /
4.0: branch
2.2: []
2.2: to_sym
2.1: log_path
2.0: assignment
1.9: each
Console#show_routes: (53.6)
17.3: puts
10.9: branch
10.9: assignment
4.0: conditions
4.0: params
3.6: inspect
3.6: []
3.4: upcase
3.2: to_s
3.2: named_routes
2.8: each
1.7: <<
1.7: routes
1.5: -
1.3: empty?
ResponderMixin#_perform_content_negotiation: (53.0)
14.9: assignment
11.8: branch
4.8: first
4.2: +
4.2: request
3.8: accept
3.6: join
3.4: to_sym
3.4: _provided_formats
3.0: empty?
3.0: ==
2.0: parse
1.8: map
1.7: params
1.6: %
1.6: compact
1.6: length
1.5: include?
1.5: []
1.4: raise
1.4: &
BuildFramework#build_framework: (51.8)
12.9: /
9.7: branch
9.6: root
7.7: assignment
4.4: []
3.9: require
3.7: exists?
2.4: length
2.2: first
2.2: ==
2.0: push_path
2.0: Array
2.0: default_framework
1.8: each
1.2: lit_fixnum
RenderMixin#partial: (50.8)
23.3: assignment
11.4: branch
5.4: send
4.2: delete
3.1: to_sym
2.9: basename
2.9: match
2.8: []
1.7: raise
1.7: respond_to?
1.5: controller_name
1.5: dirname
1.5: content_type
1.4: map
1.4: size
1.3: /
1.2: pop
1.2: join
1.2: _template_for
1.2: flatten
1.2: key?
1.2: to_s
1.2: merge
1.2: push
0.8: lit_fixnum
Route#compile: (49.2)
9.7: []
9.6: <<
9.5: assignment
8.2: branch
7.4: params
6.3: inspect
3.0: join
1.9: if_conditions
1.7: keys
1.7: merged_original_conditions
1.5: ==
1.5: map
1.5: has_key?
1.3: proc
0.4: lit_fixnum
Templates#template_paths: (48.8)
15.9: assignment
9.6: branch
4.1: dir_for
4.0: map
4.0: uniq
4.0: []
4.0: compact
2.4: _template_roots
2.4: full_const_get
2.3: first
2.2: _template_root
2.2: flatten
2.0: +
2.0: template_extensions
2.0: blank?
2.0: _abstract_subclasses
1.9: <<
1.8: each
1.8: join
LoadClasses#run: (48.7)
12.7: dir_for
8.0: branch
7.6: unshift
6.0: assignment
5.7: send
4.7: last
2.5: first
2.3: /
2.2: ==
2.1: load_classes
2.1: load_paths
2.0: load_file
1.9: each
1.9: file?
SessionMixin#setup_session: (46.4)
17.6: assignment
8.0: request
4.9: _session_id_key
4.9: cookies
4.3: []
3.5: session
2.9: set_session_id_cookie
2.7: ==
2.7: persist
2.7: branch
1.7: data
1.6: _session_secret_key
1.5: dump
1.4: new
1.4: read_cookie
1.3: hash
Behavior#resource: (43.6)
9.8: assignment
7.6: match
7.2: branch
5.6: to_route
4.8: name
3.9: []
3.0: merged_params
2.6: namespace_to_name_prefix
2.6: nil?
1.5: join
1.4: push
1.4: pop
1.4: yield
1.3: to_s
1.2: delete
1.2: block_given?
1.2: empty?
1.2: to_resource
Mongrel#process: (42.4)
18.6: assignment
11.2: branch
4.4: each
4.0: delete
3.4: body
3.0: []
2.8: call
2.6: ==
1.6: <<
1.6: header
1.6: new
1.5: params
1.4: to_i
1.4: close
1.4: ===
1.4: finished
1.3: update
1.3: replace
1.3: respond_to?
0.4: lit_fixnum
Server#daemonize: (41.6)
9.6: branch
6.0: reopen
4.2: exit
4.0: []
3.8: fork
2.2: to_hash
2.2: adapter
2.1: remove_pid_file
2.0: at_exit
2.0: setsid
2.0: umask
2.0: trap
2.0: start
2.0: chdir
2.0: run
2.0: assignment
1.9: puts
Const#none: (41.5)
35.6: freeze
3.3: *
1.3: lit_fixnum
1.3: at
Merb#merge_env: (40.6)
8.9: environment_info
8.0: assignment
7.8: branch
4.4: []
4.4: /
4.0: environment
2.5: dir_for
2.4: logger
2.2: load
2.2: warn!
2.1: exists?
2.1: <<
1.9: member?
1.9: nil?
Dispatcher#dispatch_default_exception: (40.0)
8.3: assignment
6.0: send
4.2: branch
4.0: instance_variable_set
2.8: name
2.6: split
2.5: capitalize
2.4: map
2.2: class
2.2: message
2.2: template_for
2.2: join
2.2: headers
2.0: status
2.0: merge!
1.8: is_a?
1.8: new
Server#kill: (38.7)
9.0: puts
8.2: branch
7.8: assignment
4.7: rm
2.5: read
2.3: kill
2.3: exist?
2.3: chomp
2.1: to_i
2.0: pid_file
2.0: pid_files
1.9: ==
1.9: each
1.8: run
1.8: exit
0.5: lit_fixnum
Thin#start: (37.8)
20.0: []
10.7: assignment
6.6: branch
3.2: logger
2.8: warn!
2.8: start
1.6: to_i
1.5: root
1.4: include?
1.2: change_privilege
1.2: start!
MemCacheSession#persist: (37.8)
15.2: assignment
10.3: branch
4.3: new
4.1: session_id
2.5: persist_exception_callbacks
2.5: logger
2.5: message
2.4: call
2.3: warn!
2.3: each
2.2: get
2.1: nil?
2.0: generate
1.9: is_a?
1.9: blank?
RackUpApplication#run: (35.4)
7.0: eval
6.1: []
5.8: assignment
5.6: branch
5.0: dir_for
3.5: use
3.4: new
2.7: /
1.7: run
1.4: read
1.3: to_app
1.2: require
1.2: exists?
RenderMixin#_template_for: (35.0)
17.4: assignment
10.8: branch
10.8: send
4.7: /
2.9: is_a?
2.8: _template_method_for
1.6: index
1.6: class
1.4: _absolute_template_location
1.4: _template_roots
1.2: reverse_each
Template#template_for: (34.9)
12.0: assignment
6.5: []
6.1: branch
5.4: template_extensions
5.0: join
4.8: load_template_io
4.4: inline_template
4.2: first
1.9: expand_path
Server#pid_file: (34.2)
15.1: []
10.6: assignment
4.4: log_path
4.0: /
3.8: branch
2.2: extname
2.2: join
2.2: basename
2.2: dirname
Router#generate: (33.9)
18.6: assignment
9.8: branch
4.3: nil?
4.1: reject!
3.8: is_a?
2.3: merge
2.2: []
2.1: generate_for_default_route
2.0: generate
2.0: raise
1.9: to_sym
1.9: key?
AbstractController#_dispatch: (33.2)
11.6: assignment
11.5: branch
5.8: now
3.0: _before_filters
2.8: -
2.6: _after_filters
2.6: _call_filters
1.6: action_name
1.4: call
1.4: __send__
1.4: _call_action
1.4: _filters_halted
1.3: raise
1.2: finalize_session
1.2: catch
1.2: setup_session
Request#none: (32.3)
7.2: freeze
6.5: class_eval
6.1: assignment
6.0: sclass
4.8: alias
2.4: cattr_accessor
1.2: private
1.2: each
1.2: public
1.2: branch
1.2: attr_accessor
Logger#initialize_log: (32.3)
8.3: assignment
6.0: branch
5.9: |
3.9: dirname
3.8: delimiter
3.4: open
2.1: now
1.9: httpdate
1.8: mkdir_p
1.7: write
1.7: directory?
1.5: close
1.5: exist?
1.4: respond_to?
RequestHelper#request: (31.9)
14.3: assignment
6.1: delete
2.9: +
2.8: block_pass
2.8: branch
1.7: snake_case
1.5: to_const_string
1.5: []
1.4: dispatch_multipart_to
1.4: dispatch_to
1.3: full_const_get
1.3: to_s
1.3: merge!
1.3: nil?
1.3: fake_request
1.3: split
1.3: check_request_for_route
AbstractController#_call_filters: (31.7)
11.2: branch
10.5: send
8.0: instance_eval
5.7: assignment
1.8: []
1.6: block_pass
1.6: key?
1.6: action_name
1.4: _call_filter_for_action?
1.4: _filter_condition_met?
1.2: each
Server#change_privilege: (31.6)
22.0: []
7.9: branch
4.4: puts
4.2: _change_privilege
Post#push_params: (31.0)
10.7: branch
10.4: assignment
3.7: new
3.4: is_a?
3.3: <<
3.0: each
2.0: read
2.0: path
1.9: keys
1.8: push_params
1.6: to_s
1.5: respond_to?
1.5: nil?
1.5: sort_by
Server#_change_privilege: (31.0)
13.7: assignment
5.8: branch
4.4: change_privilege
4.2: ==
4.0: puts
2.2: getgrnam
2.2: initgroups
2.2: getpwnam
2.0: uid
2.0: egid
2.0: euid
2.0: gid
AbstractController#add_filter: (30.6)
12.6: branch
6.6: assignment
5.3: raise
5.2: key?
3.4: to_s
1.9: first
1.7: last
1.5: <<
1.5: []
1.5: replace
1.4: find
1.3: include?
1.2: normalize_filters!
1.2: each_key
Server#pid_files: (30.5)
16.6: []
6.3: assignment
4.4: /
3.7: branch
2.3: log_path
2.1: extname
2.1: basename
2.1: dirname
ReloadClasses#reload: (30.3)
11.4: assignment
9.7: branch
5.1: []
4.6: dir_for
2.9: <<
2.6: each
1.9: /
1.8: mtime
1.6: ==
1.5: reload
1.5: flatten
1.5: load_paths
1.4: file?
RenderMixin#_get_layout: (30.2)
16.6: assignment
10.4: branch
5.0: content_type
4.3: _template_for
3.9: send
1.6: index
1.6: controller_name
1.5: raise
1.3: respond_to?
1.3: instance_of?
1.3: to_s
1.2: ==
Rack#none: (30.2)
19.2: autoload
11.0: register
Kernel#__caller_lines__: (29.8)
16.1: assignment
6.0: +
4.8: branch
2.7: size
2.4: -
1.6: ==
1.6: chomp
1.6: lit_fixnum
1.4: <<
1.4: to_i
1.2: >
1.2: <
1.2: readlines
1.2: []
1.2: each_with_index
Request#params: (29.6)
8.4: branch
5.1: class
4.5: merge!
3.2: multipart_params
3.2: xml_params
3.2: json_params
2.7: assignment
1.6: body_and_query_params
1.6: route_params
1.5: parse_multipart_params
1.5: parse_xml_params
1.5: parse_json_params
1.4: merge
Merb#start: (29.6)
14.7: []
7.8: branch
5.7: assignment
4.2: kill
2.0: setup
2.0: start
2.0: parse_args
1.9: ===
1.2: lit_fixnum
Route#segments_from_path: (28.8)
6.9: assignment
6.8: []
5.4: branch
4.5: <<
3.7: pre_match
3.0: gsub
2.8: empty?
1.7: post_match
1.7: intern
1.4: match
1.3: proc
0.5: lit_fixnum
Controller#none: (28.5)
6.6: include
5.5: sclass
5.5: assignment
3.5: []
2.8: private
2.2: branch
1.3: _callable_methods
1.2: *
1.1: attr_reader
1.1: hide_action
1.1: new
1.1: attr_accessor
1.1: class_inheritable_accessor
1.1: cattr_accessor
0.4: lit_fixnum
Controller#_callable_methods: (28.2)
7.5: assignment
5.5: branch
5.2: public_instance_methods
4.0: ==
2.6: _shown_actions
2.4: +
2.4: _hidden_actions
2.2: -
2.0: <<
2.0: flatten
2.0: superclass
1.8: reject
LoadClasses#remove_classes_in_file: (28.0)
11.7: branch
8.0: assignment
5.8: each
4.2: klass_hashes
2.2: remove_constant
2.1: to_s
2.0: unprotect_keys!
2.0: yield
2.0: protect_keys!
1.9: block_given?
1.9: delete
Request#params_to_query_string: (27.3)
13.1: branch
11.5: assignment
7.4: escape
4.8: params_to_query_string
4.6: map
4.2: *
Dictionary#[]: (26.9)
5.7: branch
5.3: []
4.2: shift
3.9: assignment
2.3: size
2.1: empty?
2.1: %
2.0: raise
1.9: replace
1.9: ==
1.8: new
1.8: ===
0.6: lit_fixnum
Runner#start: (26.2)
14.0: eval
6.0: []
2.4: branch
1.6: read
1.3: exit
1.3: exists?
1.1: change_privilege
1.1: assignment
0.8: lit_fixnum
Request#query_parse: (26.0)
18.0: assignment
8.0: branch
4.2: split
3.8: inject
2.3: unescape
2.1: normalize_params
2.0: to_mash
2.0: new
0.6: lit_fixnum
Inflect#clear: (25.4)
22.9: assignment
8.0: ==
7.6: branch
Irb#start: (25.4)
6.6: branch
4.0: assignment
3.9: send
2.7: sandboxed?
2.6: extend
2.6: require
1.7: merb
1.5: close_sandbox!
1.4: open_sandbox!
1.3: at_exit
1.3: exit
1.3: start
1.3: new
1.3: exists?
1.3: clear
AcceptType#to_sym: (25.3)
9.0: []
5.7: assignment
4.6: synonyms
4.0: ==
3.7: branch
2.0: available_mime_types
1.8: select
1.6: flatten
1.4: first
Request#method: (25.1)
11.4: branch
8.1: assignment
3.5: []
3.2: to_sym
2.1: class
1.9: call
1.9: http_method_overrides
1.8: downcase!
1.7: include?
1.7: each
1.6: downcase
1.5: raise
Merb#add_mime_type: (25.1)
8.7: assignment
8.5: class_eval
5.1: branch
3.5: update
1.8: +
1.8: []
1.8: first
1.7: delete
1.7: enforce!
1.7: each
0.5: lit_fixnum
Logger#none: (24.9)
7.0: class_eval
4.2: assignment
3.9: attr_reader
3.9: attr_accessor
2.6: alias
2.6: branch
1.8: lit_fixnum
1.3: each_pair
1.3: public
1.3: const_defined?
1.3: private
Server#alive?: (24.5)
7.8: branch
6.3: puts
6.0: []
4.0: assignment
2.4: read
2.2: chomp
2.0: pid_file
2.0: to_i
2.0: kill
ControllerMixin#stream_file: (23.6)
7.5: []
3.7: assignment
2.4: update
2.4: branch
1.4: send_header
1.4: call
1.4: send_status
1.4: strip
1.4: headers
1.4: merge
1.3: dup
1.2: <<
1.2: new
1.2: must_support_streaming!
ResponderMixin#content_type=: (23.2)
8.7: assignment
7.5: []
4.2: branch
3.2: available_mime_types
2.9: headers
1.7: new
1.5: raise
1.5: call
1.4: has_key?
1.4: each
Behavior#deduce_placeholders: (23.2)
10.4: assignment
7.2: []
4.0: branch
2.1: offset
2.1: lit_fixnum
1.7: count_parens_up_to
1.7: intern
1.5: sub!
1.5: ==
1.4: match
1.2: each_pair
Merb#log_file: (23.2)
10.7: []
8.1: branch
4.7: log_path
4.3: /
2.0: testing?
Router#compiled_statement: (23.0)
12.7: <<
6.6: assignment
4.0: branch
2.6: ==
2.4: compile
2.1: each_with_index
1.9: synchronize
Request#normalize_params: (22.9)
10.0: assignment
9.8: branch
5.0: []
4.8: normalize_params
4.4: <<
3.9: ==
Inflect#plural: (22.8)
13.4: assignment
5.7: branch
4.0: plural_of
3.9: []
3.9: dup
1.9: sub!
1.9: pluralization_rules
1.9: ==
HasTag#matches?: (22.6)
8.3: branch
4.4: assignment
3.8: selector
3.4: search
2.9: parse
2.8: empty?
2.6: nil?
1.8: call
1.7: string
1.6: select
Request#escape: (22.6)
3.2: size
3.0: *
2.8: unpack
2.6: join
2.4: upcase
2.3: to_s
2.2: +
2.1: gsub
2.1: branch
1.9: tr
Inflect#singularization_rules: (22.5)
12.2: assignment
6.5: branch
4.4: +
2.7: map
2.5: join
2.3: flatten
2.1: []
1.9: new
1.9: invert
Route#behavior_trace: (22.5)
6.9: send
5.9: puts
3.7: inspect
3.2: branch
2.1: reverse
2.0: assignment
1.9: map
1.7: join
AbstractController#none: (22.4)
5.5: sclass
4.4: attr_accessor
4.4: include
4.4: assignment
2.2: alias_method
2.2: class_inheritable_accessor
1.1: private
1.1: new
1.1: cattr_accessor
BootLoader#move_klass: (22.0)
6.7: to_s
6.7: subclasses
2.3: +
2.1: insert
2.1: delete
1.9: assignment
1.9: index
1.9: branch
Server#store_pid: (21.9)
5.4: branch
4.1: dirname
3.7: puts
3.7: assignment
2.1: pid
1.9: mkdir_p
1.9: write
1.8: []
1.8: directory?
1.8: pid_file
1.8: open
Behavior#array_to_code: (21.2)
10.0: branch
7.5: assignment
6.5: <<
2.4: to_s
2.3: class
2.1: raise
2.0: >
1.8: each_with_index
Behavior#concat_without_endcaps: (21.1)
10.8: branch
7.8: []
3.6: nil?
3.6: assignment
3.6: ==
1.8: +
1.0: lit_fixnum
Inflect#singular: (20.9)
13.4: assignment
4.0: singular_of
3.9: dup
3.9: []
3.8: branch
1.9: sub!
1.9: singularization_rules
Inflect#pluralization_rules: (20.8)
12.2: assignment
6.5: branch
4.4: +
2.7: map
2.5: join
2.1: flatten
1.9: []
1.9: new
Logger#set_log: (20.7)
14.5: assignment
6.2: []
4.3: branch
3.4: to_sym
1.7: environment
1.5: ==
1.4: initialize_log
Static#call: (19.3)
9.0: branch
5.4: []
3.9: assignment
2.8: serve_static
2.7: file_exist?
1.5: call
1.4: empty?
1.3: chomp
1.2: +
0.4: lit_fixnum
Behavior#merged_placeholders: (19.2)
12.7: assignment
4.2: branch
2.9: +
1.8: total_previous_captures
1.8: ancestors
1.7: ==
1.6: reverse
1.5: placeholders
1.3: each_pair
1.2: each
Router#compile: (19.0)
9.5: eval
4.3: compiled_statement
2.1: binding
2.0: puts
1.9: branch
1.1: lit_fixnum
RouteToMatcher#matches?: (18.9)
6.6: assignment
4.4: delete
4.0: branch
3.2: snake_case
2.9: ==
2.6: to_s
1.5: match_parameters
1.3: has_key?
1.3: dup
Router#capture: (18.8)
5.7: assignment
4.2: routes
4.2: named_routes
1.9: yield
1.9: dup
1.9: except
1.9: -
1.9: keys
Request#path: (18.8)
4.1: branch
3.7: uri
3.0: []
2.7: assignment
1.8: split
1.6: size
1.6: first
1.5: empty?
1.4: >
1.4: ==
1.3: squeeze
0.8: lit_fixnum
Post#to_multipart: (18.6)
11.7: +
3.5: assignment
2.4: to_multipart
2.1: branch
2.1: collect
1.9: join
ControllerMixin#send_file: (18.1)
6.0: []
2.6: branch
2.4: assignment
2.4: update
1.5: basename
1.4: merge
1.4: strip
1.4: headers
1.3: dup
1.2: <<
1.2: open
Dispatcher#none: (18.0)
5.5: sclass
3.4: new
1.7: []
1.7: assignment
1.7: attr_accessor
1.7: private
1.5: dirname
1.3: /
1.1: expand_path
LoadClasses#load_classes: (17.8)
8.3: assignment
6.0: branch
3.9: each
2.3: unshift
2.2: load_file
2.2: []
2.1: flatten
1.9: load_classes_with_requirements
AbstractController#inherited: (17.6)
8.5: class_eval
3.6: to_s
1.9: _abstract_subclasses
1.7: <<
1.7: make_module
1.7: branch
1.7: assignment
Application#call: (17.5)
2.8: +
2.6: logger
2.4: assignment
1.7: backtrace
1.7: message
1.5: join
1.2: handle
1.1: branch
1.1: status
1.1: flush
1.1: info
1.1: headers
1.1: body
0.3: lit_fixnum
Dispatcher#dispatch_redirection: (17.5)
9.0: assignment
4.0: behavior
2.0: logger
1.8: info
1.8: redirect_url
1.8: new
1.8: redirect_status
1.8: headers
Responder#parse: (17.4)
8.7: assignment
2.8: branch
2.0: []
1.8: new
1.7: size
1.6: <<
1.6: +
1.5: <
1.4: ==
1.4: sort
1.4: split
0.5: lit_fixnum
Cookies#set_cookie: (17.2)
10.1: assignment
4.4: branch
2.4: []
2.0: map
1.8: sort
1.6: join
1.5: gmtime
1.4: +
1.3: strftime
1.2: <<
SwiftipliedMongrel#start: (16.6)
4.6: []
3.6: assignment
2.6: new
1.4: to_i
1.4: logger
1.4: run
1.2: join
1.2: warn!
1.2: register
1.2: change_privilege
EventedMongrel#start: (16.6)
4.6: []
3.6: assignment
2.6: new
1.4: to_i
1.4: logger
1.4: run
1.2: join
1.2: warn!
1.2: register
1.2: change_privilege
Request#remote_ip: (16.6)
5.6: branch
4.6: []
3.1: assignment
2.6: include?
1.8: first
1.7: split
1.6: strip
1.5: empty?
1.5: reject
AbstractController#normalize_filters!: (16.4)
6.6: assignment
5.8: []
5.0: branch
3.0: Array
2.8: to_s
2.6: map
Kernel#__profile__: (16.4)
9.9: assignment
4.9: branch
1.4: yield
1.4: root
1.3: print
1.3: require
1.3: times
1.2: new
1.2: profile
1.2: open
1.2: join
0.6: lit_fixnum
RenderMixin#throw_content: (16.4)
5.0: branch
3.0: []
2.7: block_given?
2.6: <<
2.5: assignment
1.6: to_s
1.5: capture
1.5: block_pass
1.3: raise
1.2: nil?
Mongrel#start: (16.4)
4.6: []
2.6: new
2.4: assignment
1.4: to_i
1.4: logger
1.4: run
1.2: join
1.2: register
1.2: warn!
1.2: change_privilege
require "rubygems"
require "functor"
require "rbench"
fib_func = Functor.new do
given( 0 ) { 0 }
given( 1 ) { 1 }
given( Integer ) { |n| self.call( n - 1 ) + self.call( n - 2 ) }
end
correct_func = Functor.new do
given( 0 ) { 0 }
given( 1 ) { 1 }
given( lambda { |n| n > 1 } ) { |n| self.call( n - 1 ) + self.call( n - 2 ) }
end
def fib(n)
return 0 if n == 0
return 1 if n == 1
return fib(n - 1) + fib(n - 2) if n.is_a?(Integer) && n > 1
raise "You need to provide an integer"
end
RBench.run(1) do
group("fib(20)") do
report "functor" do
fib_func.call(20)
end
report "more correct functor" do
correct_func.call(20)
end
report "function" do
fib(20)
end
end
group("[1..10].map fib", 10) do
report "functor" do
[ *0..10 ].map( &fib_func )
end
report "more correct functor" do
[ *0..10 ].map( &correct_func )
end
report "function" do
[ *0..10 ].map {|x| fib(x) }
end
end
end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
# TITLE:
#
# Dictionary
#
# AUTHORS:
#
# - Jan Molic
# - Thomas Sawyer
#
# CREDIT:
#
# - Andrew Johnson (merge, to_a, inspect, shift and Hash[])
# - Jeff Sharpe (reverse and reverse!)
# - Thomas Leitner (has_key? and key?)
#
# LICENSE:
#
# Copyright (c) 2005 Jan Molic, Thomas Sawyer
#
# Ruby License
#
# This module is free software. You may use, modify, and/or redistribute this
# software under the same terms as Ruby.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# Originally ported from OrderHash 2.0, Copyright (c) 2005 jan molic
#
# LOG:
#
# - 2007.10.31 trans
# Fixed initialize so the constructor blocks correctly effected dictionary
# rather then just the internal hash.
# = Dictionary
#
# The Dictionary class is a Hash that preserves order.
# So it has some array-like extensions also. By defualt
# a Dictionary object preserves insertion order, but any
# order can be specified including alphabetical key order.
#
# == Usage
#
# Just require this file and use Dictionary instead of Hash.
#
# # You can do simply
# hsh = Dictionary.new
# hsh['z'] = 1
# hsh['a'] = 2
# hsh['c'] = 3
# p hsh.keys #=> ['z','a','c']
#
# # or using Dictionary[] method
# hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
# p hsh.keys #=> ['z','a','c']
#
# # but this don't preserve order
# hsh = Dictionary['z'=>1, 'a'=>2, 'c'=>3]
# p hsh.keys #=> ['a','c','z']
#
# # Dictionary has useful extensions: push, pop and unshift
# p hsh.push('to_end', 15) #=> true, key added
# p hsh.push('to_end', 30) #=> false, already - nothing happen
# p hsh.unshift('to_begin', 50) #=> true, key added
# p hsh.unshift('to_begin', 60) #=> false, already - nothing happen
# p hsh.keys #=> ["to_begin", "a", "c", "z", "to_end"]
# p hsh.pop #=> ["to_end", 15], if nothing remains, return nil
# p hsh.keys #=> ["to_begin", "a", "c", "z"]
# p hsh.shift #=> ["to_begin", 30], if nothing remains, return nil
#
# == Usage Notes
#
# * You can use #order_by to set internal sort order.
# * #<< takes a two element [k,v] array and inserts.
# * Use ::auto which creates Dictionay sub-entries as needed.
# * And ::alpha which creates a new Dictionary sorted by key.
class Dictionary
include Enumerable
class << self
#--
# TODO is this needed? Doesn't the super class do this?
#++
def [](*args)
hsh = new
if Hash === args[0]
hsh.replace(args[0])
elsif (args.size % 2) != 0
raise ArgumentError, "odd number of elements for Hash"
else
while !args.empty?
hsh[args.shift] = args.shift
end
end
hsh
end
# Like #new but the block sets the order.
#
def new_by(*args, &blk)
new(*args).order_by(&blk)
end
# Alternate to #new which creates a dictionary sorted by key.
#
# d = Dictionary.alpha
# d["z"] = 1
# d["y"] = 2
# d["x"] = 3
# d #=> {"x"=>3,"y"=>2,"z"=>2}
#
# This is equivalent to:
#
# Dictionary.new.order_by { |key,value| key }
def alpha(*args, &block)
new(*args, &block).order_by_key
end
# Alternate to #new which auto-creates sub-dictionaries as needed.
#
# d = Dictionary.auto
# d["a"]["b"]["c"] = "abc" #=> { "a"=>{"b"=>{"c"=>"abc"}}}
#
def auto(*args)
#AutoDictionary.new(*args)
leet = lambda { |hsh, key| hsh[key] = new(&leet) }
new(*args, &leet)
end
end
# New Dictiionary.
def initialize(*args, &blk)
@order = []
@order_by = nil
if blk
dict = self # This ensure autmatic key entry effect the
oblk = lambda{ |hsh, key| blk[dict,key] } # dictionary rather then just the interal hash.
@hash = Hash.new(*args, &oblk)
else
@hash = Hash.new(*args)
end
end
def order
reorder if @order_by
@order
end
# Keep dictionary sorted by a specific sort order.
def order_by( &block )
@order_by = block
order
self
end
# Keep dictionary sorted by key.
#
# d = Dictionary.new.order_by_key
# d["z"] = 1
# d["y"] = 2
# d["x"] = 3
# d #=> {"x"=>3,"y"=>2,"z"=>2}
#
# This is equivalent to:
#
# Dictionary.new.order_by { |key,value| key }
#
# The initializer Dictionary#alpha also provides this.
def order_by_key
@order_by = lambda { |k,v| k }
order
self
end
# Keep dictionary sorted by value.
#
# d = Dictionary.new.order_by_value
# d["z"] = 1
# d["y"] = 2
# d["x"] = 3
# d #=> {"x"=>3,"y"=>2,"z"=>2}
#
# This is equivalent to:
#
# Dictionary.new.order_by { |key,value| value }
def order_by_value
@order_by = lambda { |k,v| v }
order
self
end
#
def reorder
if @order_by
assoc = @order.collect{ |k| [k,@hash[k]] }.sort_by(&@order_by)
@order = assoc.collect{ |k,v| k }
end
@order
end
#def ==( hsh2 )
# return false if @order != hsh2.order
# super hsh2
#end
def ==(hsh2)
if hsh2.is_a?( Dictionary )
@order == hsh2.order &&
@hash == hsh2.instance_variable_get("@hash")
else
false
end
end
def [] k
@hash[ k ]
end
def fetch(k, *a, &b)
@hash.fetch(k, *a, &b)
end
# Store operator.
#
# h[key] = value
#
# Or with additional index.
#
# h[key,index] = value
def []=(k, i=nil, v=nil)
if v
insert(i,k,v)
else
store(k,i)
end
end
def insert( i,k,v )
@order.insert( i,k )
@hash.store( k,v )
end
def store( a,b )
@order.push( a ) unless @hash.has_key?( a )
@hash.store( a,b )
end
def clear
@order = []
@hash.clear
end
def delete( key )
@order.delete( key )
@hash.delete( key )
end
def each_key
order.each { |k| yield( k ) }
self
end
def each_value
order.each { |k| yield( @hash[k] ) }
self
end
def each
order.each { |k| yield( k,@hash[k] ) }
self
end
alias each_pair each
def delete_if
order.clone.each { |k| delete k if yield(k,@hash[k]) }
self
end
def values
ary = []
order.each { |k| ary.push @hash[k] }
ary
end
def keys
order
end
def invert
hsh2 = self.class.new
order.each { |k| hsh2[@hash[k]] = k }
hsh2
end
def reject( &block )
self.dup.delete_if &block
end
def reject!( &block )
hsh2 = reject &block
self == hsh2 ? nil : hsh2
end
def replace( hsh2 )
@order = hsh2.order
@hash = hsh2.hash
end
def shift
key = order.first
key ? [key,delete(key)] : super
end
def unshift( k,v )
unless @hash.include?( k )
@order.unshift( k )
@hash.store( k,v )
true
else
false
end
end
def <<(kv)
push *kv
end
def push( k,v )
unless @hash.include?( k )
@order.push( k )
@hash.store( k,v )
true
else
false
end
end
def pop
key = order.last
key ? [key,delete(key)] : nil
end
def inspect
ary = []
each {|k,v| ary << k.inspect + "=>" + v.inspect}
'{' + ary.join(", ") + '}'
end
def dup
a = []
each{ |k,v| a << k; a << v }
self.class[*a]
end
def update( hsh2 )
hsh2.each { |k,v| self[k] = v }
reorder
self
end
alias :merge! update
def merge( hsh2 )
self.dup.update(hsh2)
end
def select
ary = []
each { |k,v| ary << [k,v] if yield k,v }
ary
end
def reverse!
@order.reverse!
self
end
def reverse
dup.reverse!
end
def first
@hash[order.first]
end
def last
@hash[order.last]
end
def length
@order.length
end
alias :size :length
def empty?
@hash.empty?
end
def has_key?(key)
@hash.has_key?(key)
end
def key?(key)
@hash.key?(key)
end
def to_a
ary = []
each { |k,v| ary << [k,v] }
ary
end
def to_s
self.to_a.to_s
end
def to_hash
@hash.dup
end
def to_h
@hash.dup
end
end
hsh = {:x => :y, :z => :a, :b => :c, :d => :e, :f => :g, :h => :i, :j => :k, :l => :m, :n => :o, :p => :q, :r => :s, :t => :u}
arr = hsh.to_a
dic = Dictionary[*arr.flatten]
Benchmark.bmbm do |x|
x.report("Hash") do
TIMES.times { hsh[:b] }
end
x.report("Array") do
TIMES.times { arr.assoc(:b) }
end
x.report("Dictionary") do
TIMES.times{ dic[:b] }
end
end
require 'benchmark'
TIMES = (ARGV[0] || 10_000).to_i
Benchmark.bmbm do |x|
x.report("instance_methods.include? == true") do
TIMES.times do
Class.instance_methods.include?(:to_s) || Class.instance_methods.include?("to_s")
end
end
x.report("instance_method() rescue nil == true") do
TIMES.times do
Class.instance_method(:to_s) rescue false
end
end
x.report("instance_methods.include? == false") do
TIMES.times do
Class.instance_methods.include?(:foo) || Class.instance_methods.include?("foo")
end
end
x.report("instance_method() rescue nil == false") do
TIMES.times do
Class.instance_method(:foo) rescue false
end
end
end
# TIMES = 10_000
# user system total real
# instance_methods.include? == true 1.790000 0.010000 1.800000 ( 1.805433)
# intance_method() rescue nil == true 0.010000 0.000000 0.010000 ( 0.008334)
# instance_methods.include? == false 1.810000 0.000000 1.810000 ( 1.818613)
# intance_method() rescue nil == true 0.130000 0.010000 0.140000 ( 0.135678)
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("'.' true") { TIMES.times { "Hello.Goodbye".index(".") }}
x.report("/\./ true") { TIMES.times { "Hello.Goodbye".index(/\./) }}
x.report("'.' false") { TIMES.times { "HellooGoodbye".index(".") }}
x.report("/\./ false") { TIMES.times { "HellooGoodbye".index(/\./) }}
end
<html><head><title>Index for cyclomatic complexity</title></head>
<style>
body {
margin: 20px;
padding: 0;
font-size: 12px;
font-family: bitstream vera sans, verdana, arial, sans serif;
background-color: #efefef;
}
table {
border-collapse: collapse;
/*border-spacing: 0;*/
border: 1px solid #666;
background-color: #fff;
margin-bottom: 20px;
}
table, th, th+th, td, td+td {
border: 1px solid #ccc;
}
table th {
font-size: 12px;
color: #fc0;
padding: 4px 0;
background-color: #336;
}
th, td {
padding: 4px 10px;
}
td {
font-size: 13px;
}
.class_name {
font-size: 17px;
margin: 20px 0 0;
}
.class_complexity {
margin: 0 auto;
}
.class_complexity>.class_complexity {
margin: 0;
}
.class_total_complexity, .class_total_lines, .start_token_count, .file_count {
font-size: 13px;
font-weight: bold;
}
.class_total_complexity, .class_total_lines {
color: #c00;
}
.start_token_count, .file_count {
color: #333;
}
.warning {
background-color: yellow;
}
.error {
background-color: #f00;
}
</style>
<body>
<h1>Index for cyclomatic complexity</h1>
<hr/>
<h2 class="class_name">Analyzed Files</h2>
<ul>
<li>
<p class="file_name"><a href="./lib/merb-core/autoload.rb_cyclo.html">lib/merb-core/autoload.rb</a>
</li>
</ul>
</body></html>
module Language
module English
# = English Nouns Number Inflection.
#
# This module provides english singular <-> plural noun inflections.
module Inflect
@singular_of = {}
@plural_of = {}
@singular_rules = []
@plural_rules = []
class << self
# Define a general exception.
def word(singular, plural=nil)
plural = singular unless plural
singular_word(singular, plural)
plural_word(singular, plural)
end
# Define a singularization exception.
def singular_word(singular, plural)
@singular_of[plural] = singular
end
# Define a pluralization exception.
def plural_word(singular, plural)
@plural_of[singular] = plural
end
# Define a general rule.
def rule(singular, plural)
singular_rule(singular, plural)
plural_rule(singular, plural)
end
# Define a singularization rule.
def singular_rule(singular, plural)
@singular_rules << [singular, plural]
end
# Define a plurualization rule.
def plural_rule(singular, plural)
@plural_rules << [singular, plural]
end
# Read prepared singularization rules.
def singularization_rules
return @singularization_rules if @singularization_rules
sorted = @singular_rules.sort_by{ |s, p| "#{p}".size }.reverse
@singularization_rules = sorted.collect do |s, p|
[ /#{p}$/, "#{s}" ]
end
end
# Read prepared pluralization rules.
def pluralization_rules
return @pluralization_rules if @pluralization_rules
sorted = @plural_rules.sort_by{ |s, p| "#{s}".size }.reverse
@pluralization_rules = sorted.collect do |s, p|
[ /#{s}$/, "#{p}" ]
end
end
#
def plural_of
@plural_of
end
#
def singular_of
@singular_of
end
# Convert an English word from plurel to singular.
#
# "boys".singular #=> boy
# "tomatoes".singular #=> tomato
#
def singular(word)
if result = singular_of[word]
return result.dup
end
result = word.dup
singularization_rules.each do |(match, replacement)|
break if result.gsub!(match, replacement)
end
return result
end
# Alias for #singular (a Railism).
#
alias_method(:singularize, :singular)
# Convert an English word from singular to plurel.
#
# "boy".plural #=> boys
# "tomato".plural #=> tomatoes
#
def plural(word)
if result = plural_of[word]
return result.dup
end
#return self.dup if /s$/ =~ self # ???
result = word.dup
pluralization_rules.each do |(match, replacement)|
break if result.gsub!(match, replacement)
end
return result
end
# Alias for #plural (a Railism).
alias_method(:pluralize, :plural)
end
# One argument means singular and plural are the same.
word 'equipment'
word 'information'
word 'money'
word 'species'
word 'series'
word 'fish'
word 'sheep'
word 'moose'
word 'hovercraft'
word 'bass'
# Two arguments defines a singular and plural exception.
word 'Swiss' , 'Swiss'
word 'life' , 'lives'
word 'wife' , 'wives'
word 'virus' , 'viri'
word 'octopus' , 'octopi'
#word 'cactus' , 'cacti'
word 'goose' , 'geese'
word 'criterion' , 'criteria'
word 'alias' , 'aliases'
word 'status' , 'statuses'
word 'axis' , 'axes'
word 'crisis' , 'crises'
word 'testis' , 'testes'
word 'child' , 'children'
word 'person' , 'people'
word 'quiz' , 'quizes'
word 'matrix' , 'matrices'
word 'vertex' , 'vetices'
word 'index' , 'indices'
word 'ox' , 'oxen'
word 'mouse' , 'mice'
word 'louse' , 'lice'
word 'thesis' , 'theses'
word 'analysis' , 'analyses'
# One-way singularization exception (convert plural to singular).
singular_word 'cactus', 'cacti'
# General rules.
rule 'hive' , 'hives'
rule 'rf' , 'rves'
rule 'af' , 'aves'
rule 'ero' , 'eroes'
rule 'man' , 'men'
rule 'ch' , 'ches'
rule 'sh' , 'shes'
rule 'ss' , 'sses'
rule 'ta' , 'tum'
rule 'ia' , 'ium'
rule 'ra' , 'rum'
rule 'ay' , 'ays'
rule 'ey' , 'eys'
rule 'oy' , 'oys'
rule 'uy' , 'uys'
rule 'y' , 'ies'
rule 'x' , 'xes'
rule 'lf' , 'lves'
rule 'us' , 'uses'
rule '' , 's'
# One-way singular rules.
singular_rule 'of' , 'ofs' # proof
singular_rule 'o' , 'oes' # hero, heroes
singular_rule 'f' , 'ves'
# One-way plural rules.
plural_rule 'fe' , 'ves' # safe, wife
plural_rule 's' , 'ses'
end
end
end
class String
def english_singular
Language::English::Inflect.singular(self)
end
def english_plural
Language::English::Inflect.plural(self)
end
end
require 'singleton'
# The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
# and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
# in inflections.rb.
module Inflector
# A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
# inflection rules. Examples:
#
# Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1\2en'
# inflect.singular /^(ox)en/i, '\1'
#
# inflect.irregular 'octopus', 'octopi'
#
# inflect.uncountable "equipment"
# end
#
# New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
# pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
# already have been loaded.
class Inflections
include Singleton
attr_reader :plurals, :singulars, :uncountables
def initialize
@plurals, @singulars, @uncountables = [], [], []
end
# Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
def plural(rule, replacement)
@plurals.insert(0, [rule, replacement])
end
# Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
# The replacement should always be a string that may include references to the matched data from the rule.
def singular(rule, replacement)
@singulars.insert(0, [rule, replacement])
end
# Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
# for strings, not regular expressions. You simply pass the irregular in singular and plural form.
#
# Examples:
# irregular 'octopus', 'octopi'
# irregular 'person', 'people'
def irregular(singular, plural)
plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
end
# Add uncountable words that shouldn't be attempted inflected.
#
# Examples:
# uncountable "money"
# uncountable "money", "information"
# uncountable %w( money information rice )
def uncountable(*words)
(@uncountables << words).flatten!
end
# Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type,
# the options are: :plurals, :singulars, :uncountables
#
# Examples:
# clear :all
# clear :plurals
def clear(scope = :all)
case scope
when :all
@plurals, @singulars, @uncountables = [], [], []
else
instance_variable_set "@#{scope}", []
end
end
end
extend self
def inflections
if block_given?
yield Inflections.instance
else
Inflections.instance
end
end
# Returns the plural form of the word in the string.
#
# Examples
# "post".pluralize #=> "posts"
# "octopus".pluralize #=> "octopi"
# "sheep".pluralize #=> "sheep"
# "words".pluralize #=> "words"
# "the blue mailman".pluralize #=> "the blue mailmen"
# "CamelOctopus".pluralize #=> "CamelOctopi"
def pluralize(word)
result = word.to_s.dup
if inflections.uncountables.include?(result.downcase)
result
else
inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result
end
end
# The reverse of pluralize, returns the singular form of a word in a string.
#
# Examples
# "posts".singularize #=> "post"
# "octopi".singularize #=> "octopus"
# "sheep".singluarize #=> "sheep"
# "word".singluarize #=> "word"
# "the blue mailmen".singularize #=> "the blue mailman"
# "CamelOctopi".singularize #=> "CamelOctopus"
def singularize(word)
result = word.to_s.dup
if inflections.uncountables.include?(result.downcase)
result
else
inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
result
end
end
# By default, camelize converts strings to UpperCamelCase. If the argument to camelize
# is set to ":lower" then camelize produces lowerCamelCase.
#
# camelize will also convert '/' to '::' which is useful for converting paths to namespaces
#
# Examples
# "active_record".camelize #=> "ActiveRecord"
# "active_record".camelize(:lower) #=> "activeRecord"
# "active_record/errors".camelize #=> "ActiveRecord::Errors"
# "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
if first_letter_in_uppercase
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
else
lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
end
end
# Capitalizes all the words and replaces some characters in the string to create
# a nicer looking title. Titleize is meant for creating pretty output. It is not
# used in the Rails internals.
#
# titleize is also aliased as as titlecase
#
# Examples
# "man from the boondocks".titleize #=> "Man From The Boondocks"
# "x-men: the last stand".titleize #=> "X Men: The Last Stand"
def titleize(word)
humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
end
# The reverse of +camelize+. Makes an underscored form from the expression in the string.
#
# Changes '::' to '/' to convert namespaces to paths.
#
# Examples
# "ActiveRecord".underscore #=> "active_record"
# "ActiveRecord::Errors".underscore #=> active_record/errors
def underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
# Replaces underscores with dashes in the string.
#
# Example
# "puni_puni" #=> "puni-puni"
def dasherize(underscored_word)
underscored_word.gsub(/_/, '-')
end
# Capitalizes the first word and turns underscores into spaces and strips _id.
# Like titleize, this is meant for creating pretty output.
#
# Examples
# "employee_salary" #=> "Employee salary"
# "author_id" #=> "Author"
def humanize(lower_case_and_underscored_word)
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
end
# Removes the module part from the expression in the string
#
# Examples
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
# "Inflections".demodulize #=> "Inflections"
def demodulize(class_name_in_module)
class_name_in_module.to_s.gsub(/^.*::/, '')
end
# Create the name of a table like Rails does for models to table names. This method
# uses the pluralize method on the last word in the string.
#
# Examples
# "RawScaledScorer".tableize #=> "raw_scaled_scorers"
# "egg_and_ham".tableize #=> "egg_and_hams"
# "fancyCategory".tableize #=> "fancy_categories"
def tableize(class_name)
pluralize(underscore(class_name))
end
# Create a class name from a table name like Rails does for table names to models.
# Note that this returns a string and not a Class. (To convert to an actual class
# follow classify with constantize.)
#
# Examples
# "egg_and_hams".classify #=> "EggAndHam"
# "post".classify #=> "Post"
def classify(table_name)
# strip out any leading schema name
camelize(singularize(table_name.to_s.sub(/.*\./, '')))
end
# Creates a foreign key name from a class name.
# +separate_class_name_and_id_with_underscore+ sets whether
# the method should put '_' between the name and 'id'.
#
# Examples
# "Message".foreign_key #=> "message_id"
# "Message".foreign_key(false) #=> "messageid"
# "Admin::Post".foreign_key #=> "post_id"
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
end
# Constantize tries to find a declared constant with the name specified
# in the string. It raises a NameError when the name is not in CamelCase
# or is not initialized.
#
# Examples
# "Module".constantize #=> Module
# "Class".constantize #=> Class
def constantize(camel_cased_word)
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
Object.module_eval("::#{$1}", __FILE__, __LINE__)
end
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#
# Examples
# ordinalize(1) # => "1st"
# ordinalize(2) # => "2nd"
# ordinalize(1002) # => "1002nd"
# ordinalize(1003) # => "1003rd"
def ordinalize(number)
if (11..13).include?(number.to_i % 100)
"#{number}th"
else
case number.to_i % 10
when 1: "#{number}st"
when 2: "#{number}nd"
when 3: "#{number}rd"
else "#{number}th"
end
end
end
end
Inflector.inflections do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/s$/i, 's')
inflect.plural(/(ax|test)is$/i, '\1es')
inflect.plural(/(octop|vir)us$/i, '\1i')
inflect.plural(/(alias|status)$/i, '\1es')
inflect.plural(/(bu)s$/i, '\1ses')
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
inflect.plural(/([ti])um$/i, '\1a')
inflect.plural(/sis$/i, 'ses')
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
inflect.plural(/(hive)$/i, '\1s')
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
inflect.plural(/(matr|vert|ind)ix|ex$/i, '\1ices')
inflect.plural(/([m|l])ouse$/i, '\1ice')
inflect.plural(/^(ox)$/i, '\1en')
inflect.plural(/(quiz)$/i, '\1zes')
inflect.singular(/s$/i, '')
inflect.singular(/(n)ews$/i, '\1ews')
inflect.singular(/([ti])a$/i, '\1um')
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
inflect.singular(/(^analy)ses$/i, '\1sis')
inflect.singular(/([^f])ves$/i, '\1fe')
inflect.singular(/(hive)s$/i, '\1')
inflect.singular(/(tive)s$/i, '\1')
inflect.singular(/([lr])ves$/i, '\1f')
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
inflect.singular(/(s)eries$/i, '\1eries')
inflect.singular(/(m)ovies$/i, '\1ovie')
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
inflect.singular(/([m|l])ice$/i, '\1ouse')
inflect.singular(/(bus)es$/i, '\1')
inflect.singular(/(o)es$/i, '\1')
inflect.singular(/(shoe)s$/i, '\1')
inflect.singular(/(cris|ax|test)es$/i, '\1is')
inflect.singular(/(octop|vir)i$/i, '\1us')
inflect.singular(/(alias|status)es$/i, '\1')
inflect.singular(/^(ox)en/i, '\1')
inflect.singular(/(vert|ind)ices$/i, '\1ex')
inflect.singular(/(matr)ices$/i, '\1ix')
inflect.singular(/(quiz)zes$/i, '\1')
inflect.irregular('person', 'people')
inflect.irregular('man', 'men')
inflect.irregular('child', 'children')
inflect.irregular('sex', 'sexes')
inflect.irregular('move', 'moves')
inflect.uncountable(%w(equipment information rice money species series fish sheep))
end
module Inflections
def pluralize
Inflector.pluralize(self)
end
def singularize
Inflector.singularize(self)
end
def camelize(first_letter = :upper)
case first_letter
when :upper then Inflector.camelize(self, true)
when :lower then Inflector.camelize(self, false)
end
end
alias_method :camelcase, :camelize
def titleize
Inflector.titleize(self)
end
alias_method :titlecase, :titleize
def underscore
Inflector.underscore(self)
end
def dasherize
Inflector.dasherize(self)
end
def demodulize
Inflector.demodulize(self)
end
def tableize
Inflector.tableize(self)
end
def classify
Inflector.classify(self)
end
def humanize
Inflector.humanize(self)
end
def foreign_key(separate_class_name_and_id_with_underscore = true)
Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
end
def constantize
Inflector.constantize(self)
end
end
class String
include Inflections
end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("English boy => boys") do
TIMES.times { "boy".english_plural }
end
x.report("Rails boy => boys") do
TIMES.times { "boy".pluralize }
end
x.report("English boys => boy") do
TIMES.times { "boys".english_singular }
end
x.report("Rails boy => boys") do
TIMES.times { "boys".singularize }
end
x.report("English wife => wives") do
TIMES.times { "wife".english_plural }
end
x.report("Rails wife => wives") do
TIMES.times { "wife".pluralize }
end
x.report("English wives => wife") do
TIMES.times { "wives".english_singular }
end
x.report("Rails wives => wife") do
TIMES.times { "wives".singularize }
end
x.report("English dwarf => dwarves") do
TIMES.times { "dwarf".english_plural }
end
x.report("Rails dwarf => dwarves") do
TIMES.times { "dwarf".pluralize }
end
x.report("English dwarves => dwarf") do
TIMES.times { "dwarves".english_singular }
end
x.report("Rails dwarves => dwarf") do
TIMES.times { "dwarves".singularize }
end
end
# TIMES = 100_000
# user system total real
# English boy => boys 1.310000 0.000000 1.310000 ( 1.332678)
# Rails boy => boys 2.830000 0.000000 2.830000 ( 2.846847)
#
# English boys => boy 1.540000 0.010000 1.550000 ( 1.576141)
# Rails boy => boys 3.140000 0.010000 3.150000 ( 3.201089)
#
# English wife => wives 0.250000 0.010000 0.260000 ( 0.261200)
# Rails wife => wives 2.150000 0.010000 2.160000 ( 2.199219)
#
# English wives => wife 0.250000 0.000000 0.250000 ( 0.264623)
# Rails wives => wife 3.130000 0.020000 3.150000 ( 3.192153)
#
# English dwarf => dwarves 1.120000 0.000000 1.120000 ( 1.159888)
# Rails dwarf => dwarves 2.150000 0.010000 2.160000 ( 2.329601)
#
# English dwarves => dwarf 1.060000 0.010000 1.070000 ( 1.338925)
# Rails dwarves => dwarf 2.900000 0.020000 2.920000 ( 2.931470)
require "rubygems"
require "inline"
class Class
def class_inheritable_reader(ivar)
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{ivar}
return @#{ivar} if self == #{self}
if defined?(@#{ivar})
@#{ivar}
else
@#{ivar} = superclass.#{ivar}.dup
end
end
RUBY
end
def class_inheritable_writer(ivar)
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{ivar}=(obj)
@#{ivar} = obj
end
RUBY
end
def class_inheritable_array_reader(ivar)
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{ivar}
return @#{ivar} || [] if self == #{self}
ret = [] | (@#{ivar} || []) | superclass.#{ivar}
end
RUBY
end
def class_inheritable_accessor(ivar)
class_inheritable_reader(ivar)
class_inheritable_writer(ivar)
end
def class_inheritable_array_accessor(ivar)
class_inheritable_array_reader(ivar)
class_inheritable_writer(ivar)
end
end
class Foo
end
class Bar < Foo
end
class Baz < Bar
end
class Foo
class_inheritable_accessor(:zoo)
end
Foo.zoo = [1]
p Foo.zoo
Bar.zoo.clear
p Foo.zoo
p Bar.zoo
class Foo
def initialize
@original = method(:foo)
end
def foo(i)
i + 1
end
def bar1
i = 0
while i < 1_000
foo(i)
i += 1
end
end
def bar2
if method(:foo) == @original
i = 0
while i < 1_000
i + 1
i += 1
end
else
i = 0
while i < 1_000
foo(i)
i += 1
end
end
end
end
Foo.new.bar1
Foo.new.bar2
FOO = Foo.new
require "rubygems"
require "rbench"
RBench.run(1_000) do
report("regular") do
FOO.bar1
end
report("inlined") do
FOO.bar2
end
end
require 'benchmark'
require 'zlib'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("instantiate") { TIMES.times { [1,2] }}
x.report("zlib") { TIMES.times { 1.object_id + 2.object_id }}
end
require "rubygems"
require "rbench"
PROC = proc {|text| "Hello my name is #{text}"}
def meth(text)
"Hello my name is #{text}"
end
RBench.run(1_000_000) do
report("interpolation") do
merb = "Merb"
"Hello my name is #{merb}"
end
report("proc") do
merb = "Merb"
PROC[merb]
end
report("meth") do
merb = "Merb"
meth(merb)
end
end
Copyright (c) 2008 Engine Yard Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
class Foo
def meth1
1
end
end
class Bar
(1..10_000).each do |num|
class_eval <<-METH, __FILE__, __LINE__
def meth#{num}
#{num}
end
METH
end
end
Benchmark.bmbm do |x|
x.report("single") { TIMES.times { Foo.new.meth1 }}
x.report("lots") { TIMES.times { Bar.new.meth1 }}
end
# TIMES == 1_000_000
# user system total real
# single 0.640000 0.000000 0.640000 ( 0.638838)
# lots 0.640000 0.000000 0.640000 ( 0.635349)
#!/usr/bin/env ruby
require "merb-core"
if ARGV[0] && ARGV[0] =~ /^[^-]/
ARGV.push "-H"
end
unless %w[-a --adapter -i --irb-console -r --script-runner].any? { |o| ARGV.index(o) }
ARGV.push *%w[-a mongrel]
end
Merb.start
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__),"..","lib","merb-core","test","run_specs")
run_specs ARGV
require 'autotest'
# require File.dirname(__FILE__) + '/textmate'
$VERBOSE = false
# cloned from Rspec's autotest settings, but modified
# to cope w/ Merb's specs directory layout
# ==== Merb Source Autotest Rules
# 1. Updating a spec reruns that spec
# 2. Updating a spec_helper reruns all specs at that level and below
# 3. Updating a file under controller (i.e. abstract_controller.rb)
# reruns all the specs under (public|private)/abstract_controller
# 4. Updating a file under controller/mixins (e.g. render)
# reruns all specs under
# (public|private)/(abstract_controller|controller)/render_spec.rb
# 5. Updating a file directly under merb-core (e.g. core_ext.rb)
# reruns all the specs under spec/(public|private)/core_ext
# 6. Updating merb.rb reruns all specs
class RspecCommandError < StandardError; end
class Autotest::MerbsourceRspec < Autotest
Autotest.add_hook :initialize do |at|
at.clear_mappings
at.add_exception(/\.git|log|coverage|doc/)
# See above for human-readable descriptions of these rules
# 1 above
at.add_mapping(%r{^spec/.*_spec\.rb$}) { |filename, _| filename}
# 2 above
at.add_mapping(%r{^spec/spec_helper\.rb$}) { |_, m| at.files_matching %r{^spec/.*_spec\.rb$} }
at.add_mapping(%r{^spec/(.*)/spec_helper\.rb$}) { |_, m| at.files_matching %r{^spec/#{m[1]}/.*_spec\.rb$} }
# 3 above
at.add_mapping(%r{^lib/merb-core/controller/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec/(public|private)/abstract_controller/.*_spec\.rb} }
# 4 above
at.add_mapping(%r{^lib/merb-core/controller/mixins/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec/(public|private)/(abstract_)?controller/#{m[1]}_spec\.rb} }
# 5 above
at.add_mapping(%r{^lib/merb-core/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec/(public|private)/#{m[1]}/.*_spec\.rb} }
# 6 above
at.add_mapping(%r{^lib/merb\.rb$}) { at.files_matching %r{^spec/[^/]*_spec\.rb$} }
end
def initialize(kernel = Kernel, separator = File::SEPARATOR, alt_separator = File::ALT_SEPARATOR) # :nodoc:
super() # need parens so that Ruby doesn't pass our args
# to the superclass version which takes none..
@kernel, @separator, @alt_separator = kernel, separator, alt_separator
@spec_command = spec_command
end
attr_accessor :failures
def failed_results(results)
results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
end
def handle_results(results)
@failures = failed_results(results)
@files_to_test = consolidate_failures @failures
unless $TESTING
if @files_to_test.empty?
hook :green
else
hook :red
end
end
@tainted = true unless @files_to_test.empty?
end
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
find_files.keys.select { |f| f =~ /spec\// }.each do |f|
if failed_trace =~ Regexp.new(f)
filters[f] << spec
break
end
end
end
filters
end
def make_test_cmd(files_to_test)
"#{ruby} -S #{@spec_command} #{test_cmd_options} #{files_to_test.keys.flatten.join(' ')}"
end
def test_cmd_options
# '-O specs/spec.opts' if File.exist?('specs/spec.opts')
end
# Finds the proper spec command to use. Precendence
# is set in the lazily-evaluated method spec_commands. Alias + Override
# that in ~/.autotest to provide a different spec command
# then the default paths provided.
def spec_command
if cmd = spec_commands.detect { |c| File.exist? c }
@alt_separator ? (cmd.gsub @separator, @alt_separator) : cmd
else
raise RspecCommandError, 'No spec command could be found!'
end
end
# Merb specs must be run 1 at a time, so use our special runner
def spec_commands
[File.join('bin', 'merb-specs')]
end
end
require "rubygems"
require "rbench"
SYM = {:sym => [:sym]}
RBench.run(100_000) do
report "[1]" do
[:sym]
end
report "hash" do
SYM[:sym]
end
end
## TEMPLATES
# Render an action
render :symbol
# Render a string
render "string"
# Render an object; will call to_#{content-type} on this if the default template is not found
display @obj
# Provide an alternative default thing to render; note that we can use strings here for template paths
# because strings would never fail and fallback to the @obj
display @obj, :symbol
display @obj, "full/path/to/template"
# Render a template
render_template "full/path/to/template"
# Render with a mime-type (same as render, but with added mime-type set)
render_json :symbol
render_json "string"
# Render nothing at all
render_nothing
# TEMPLATE OPTIONS (all functions above can use these options)
# :format can be used to override the mime-type arrived at via content-negotiation
render :symbol, :format => :xml
# :status can set the status that will be returned to the browser
render :symbol, :status => Successful::Accepted
# or
render :symbol, :status => 202
# :layout sets the layout to use; default: controller.to_path || :application; :none means no layout
render :symbol, :layout => :none
## PARTIALS
# Render a partial
partial :symbol
# Render a partial with an object (it will default to the local var "symbol" in the partial)
partial :symbol, :with => @object
partial :symbol, :with => @object, :as => "something"
# Render a partial with a collection of objects (same :as semantics)
partial :symbol, :with => [col, lec, tion]
partial :symbol, :with => [col, lec, tion], :as => "name"
require "rubygems"
require "benchwarmer"
x = true
Benchmark.warmer(10_000_000) do
report("multiline") { if x; true; end }
report("one-liner") { true if x }
end
6/18/2008:
* Modified the public interface to Merb::Template.inline_template to accept a File or VirtualFile
** For files, templates are now inlined the same way, except do File.open(path) instead of path
** To inline Virtual Files, create a Virtual File via VirtualFile.new(string, path), which will use
the path for later attempts to find the template via Merb::Template.template_for
require "rubygems"
require "rbench"
require "erubis"
require "erubis/preprocessing"
def link_to(contents, url)
"<a href='#{url}'>#{contents}</a>"
end
class Templates
end
REGULAR_TEXT = %{<%= link_to("w00t", "http://www.example.com") %>}
Erubis::Eruby.new(REGULAR_TEXT).def_method(Templates, "regular")
PREPROCESSED_TEXT = %{[%= link_to("w00t", "http://www.example.com") %]}
pre_text = Erubis::PreprocessingEruby.new(nil).process(PREPROCESSED_TEXT)
Erubis::Eruby.new(pre_text).def_method(Templates, "preprocessed")
TEMPLATES = Templates.new
p Templates.new.preprocessed
p Templates.new.regular
RBench.run(1_000_000) do
report("regular") do
TEMPLATES.regular()
end
report("preprocessed") do
TEMPLATES.preprocessed()
end
end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
hsh = {:controller => "foo", :action => "bar", :mime => "baz", :type => "bat"}
prock = proc {|hsh| "#{hsh[:controller]}/#{hsh[:action]}.#{hsh[:mime]}.#{hsh[:type]}" }
evall = "\"\#{hsh[:controller]}/\#{hsh[:action]}.\#{hsh[:mime]}.\#{hsh[:type]}\""
gsubb = ":controller/:action.:mime.:type"
def meth(hsh)
"#{hsh[:controller]}/#{hsh[:action]}.#{hsh[:mime]}.#{hsh[:type]}"
end
Benchmark.bmbm do |x|
x.report("proc") do
TIMES.times do
prock.call(hsh)
end
end
x.report("eval") do
TIMES.times do
eval evall, binding, __FILE__, __LINE__
end
end
x.report("gsub") do
TIMES.times do
gsubb.gsub(/(:controller|:action|:mime|:type)/) {|g| hsh[g[1..-1].to_sym] }
end
end
x.report("meth") do
TIMES.times do
meth(hsh)
end
end
end
# TIMES == 100_000
# user system total real
# proc 0.350000 0.000000 0.350000 ( 0.346125)
# eval 1.400000 0.000000 1.400000 ( 1.407556)
# gsub 1.330000 0.000000 1.330000 ( 1.325826)
# meth 0.320000 0.000000 0.320000 ( 0.320849)
6/22/2008:
Erubis modified:
* <%= %> now can take a block, so <%= helper do %>Hello<% end %> now works
* Erubis buffer is now an ivar (@_erb_buf), which eliminates the need for
eval in capture helpers.
CONSEQUENCE:
Helpers that take a block should simply return a string, and should not
use concat. Example:
def my_helper(&blk)
"My helper says #{capture(&blk)}."
end
require "rubygems"
require "rbench"
require "activesupport"
class StringQuestioneer < String
def method_missing(method_name, *arguments)
if method_name.to_s.ends_with?("?")
self == method_name.to_s[0..-2]
else
super
end
end
end
class ImprovedQuestioneer < String
def method_missing(method_name, *arguments)
if method_name.to_s =~ /(.*)\?$/
self == $1
else
super
end
end
end
class AwesomeQuestioneer < String
def initialize(str)
class << self; self; end.class_eval <<-RUBY
def #{str}?
true
end
RUBY
end
def method_missing(meth, *args)
meth.to_s[-1] == ?? ? false : super
end
end
S_QUESTIONEER = StringQuestioneer.new("awesome")
I_QUESTIONEER = ImprovedQuestioneer.new("awesome")
B_QUESTIONEER = AwesomeQuestioneer.new("awesome")
AWESOME = "awesome"
RBench.run(100_000) do
group "true" do
report "questioneer" do
I_QUESTIONEER.awesome?
end
report "improved_questioneer" do
I_QUESTIONEER.awesome?
end
report "awesome_questioneer" do
B_QUESTIONEER.awesome?
end
report "==" do
AWESOME == "awesome"
end
end
group "false" do
report "questioneer" do
I_QUESTIONEER.not_awesome?
end
report "improved_questioneer" do
I_QUESTIONEER.not_awesome?
end
report "awesome_questioneer" do
B_QUESTIONEER.not_awesome?
end
report "==" do
AWESOME == "not_awesome"
end
end
end
# Results |
# --true--------------------------------
# questioneer 0.480 |
# improved_questioneer 0.465 |
# awesome_questioneer 0.028 |
# == 0.105 |
# --false-------------------------------
# questioneer 0.466 |
# improved_questioneer 0.465 |
# awesome_questioneer 0.284 |
# == 0.098 |
require "rubygems"
require "rack"
class HelloWorld
def call(env)
[200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
end
end
Rack::Handler::Mongrel.run(HelloWorld.new, :Port => 9292)
require "rake"
require "rake/clean"
require "rake/gempackagetask"
require "rake/rdoctask"
require "rake/testtask"
require "spec/rake/spectask"
require "fileutils"
require "extlib"
def __DIR__
File.dirname(__FILE__)
end
require __DIR__ + "/tools/rakehelp"
require __DIR__ + "/tools/annotation_extract"
include FileUtils
require "lib/merb-core/version"
require "lib/merb-core/test/run_specs"
require 'lib/merb-core/tasks/merb_rake_helper'
##############################################################################
# Package && release
##############################################################################
RUBY_FORGE_PROJECT = "merb"
PROJECT_URL = "http://merbivore.com"
PROJECT_SUMMARY = "Merb. Pocket rocket web framework."
PROJECT_DESCRIPTION = PROJECT_SUMMARY
AUTHOR = "Ezra Zygmuntowicz"
EMAIL = "ez@engineyard.com"
GEM_NAME = "merb-core"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
GEM_VERSION = Merb::VERSION + PKG_BUILD
RELEASE_NAME = "REL #{GEM_VERSION}"
require "extlib/tasks/release"
spec = Gem::Specification.new do |s|
s.name = GEM_NAME
s.version = GEM_VERSION
s.platform = Gem::Platform::RUBY
s.author = AUTHOR
s.email = EMAIL
s.homepage = PROJECT_URL
s.summary = PROJECT_SUMMARY
s.bindir = "bin"
s.description = PROJECT_DESCRIPTION
s.executables = %w( merb )
s.require_path = "lib"
s.files = %w( LICENSE README Rakefile TODO ) + Dir["{docs,bin,spec,lib,examples,app_generators,merb_generators,merb_default_generators,rspec_generators,test_unit_generators,script}/**/*"]
# rdoc
s.has_rdoc = true
s.extra_rdoc_files = %w( README LICENSE TODO )
#s.rdoc_options += RDOC_OPTS + ["--exclude", "^(app|uploads)"]
# Dependencies
s.add_dependency "extlib", ">=0.9.3"
s.add_dependency "erubis"
s.add_dependency "rake"
s.add_dependency "json_pure"
s.add_dependency "rspec"
s.add_dependency "rack"
s.add_dependency "mime-types"
# Requirements
s.requirements << "install the json gem to get faster json parsing"
s.required_ruby_version = ">= 1.8.4"
end
Rake::GemPackageTask.new(spec) do |package|
package.gem_spec = spec
end
desc "Run :package and install the resulting .gem"
task :install => :package do
sh %{#{sudo} gem install #{install_home} --local pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
end
desc "Run :package and install the resulting .gem with jruby"
task :jinstall => :package do
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{Merb::VERSION}.gem --no-rdoc --no-ri}
end
desc "Run :clean and uninstall the .gem"
task :uninstall => :clean do
sh %{#{sudo} gem uninstall #{NAME}}
end
CLEAN.include ["**/.*.sw?", "pkg", "lib/*.bundle", "*.gem", "doc/rdoc", ".config", "coverage", "cache"]
desc "Run the specs."
task :default => :specs
task :merb => [:clean, :rdoc, :package]
##############################################################################
# Github
##############################################################################
namespace :github do
desc "Update Github Gemspec"
task :update_gemspec do
skip_fields = %w(new_platform original_platform)
integer_fields = %w(specification_version)
result = "Gem::Specification.new do |s|\n"
spec.instance_variables.each do |ivar|
value = spec.instance_variable_get(ivar)
name = ivar.split("@").last
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
if name == "dependencies"
value.each do |d|
dep, *ver = d.to_s.split(" ")
result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
end
else
case value
when Array
value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
when String
value = value.to_i if integer_fields.include?(name)
value = value.inspect
else
value = value.to_s.inspect
end
result << " s.#{name} = #{value}\n"
end
end
result << "end"
File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
end
end
##############################################################################
# Documentation
##############################################################################
task :doc => [:rdoc]
namespace :doc do
Rake::RDocTask.new do |rdoc|
files = ["README", "LICENSE", "CHANGELOG", "lib/**/*.rb"]
rdoc.rdoc_files.add(files)
rdoc.main = "README"
rdoc.title = "Merb Docs"
rdoc.template = __DIR__ + "/tools/allison-2.0.2/lib/allison.rb"
rdoc.rdoc_dir = "doc/rdoc"
rdoc.options << "--line-numbers" << "--inline-source"
end
desc "run webgen"
task :webgen do
sh %{cd doc/site; webgen}
end
desc "rdoc to rubyforge"
task :rubyforge do
# sh %{rake doc}
sh %{#{sudo} chmod -R 755 doc} unless windows?
sh %{/usr/bin/scp -r -p doc/rdoc/* ezmobius@rubyforge.org:/var/www/gforge-projects/merb}
end
end
##############################################################################
# rSpec & rcov
##############################################################################
desc "Run :specs, :rcov"
task :aok => [:specs, :rcov]
# desc "Run all specs"
# Spec::Rake::SpecTask.new("specs") do |t|
# t.spec_opts = ["--format", "specdoc", "--colour"]
# t.spec_files = Dir["spec/**/*_spec.rb"].sort
# end
def setup_specs(name, spec_cmd='spec', run_opts = "-c -f s")
desc "Run all specs (#{name})"
task "specs:#{name}" do
run_specs("spec/**/*_spec.rb", spec_cmd, ENV['RSPEC_OPTS'] || run_opts)
end
desc "Run private specs (#{name})"
task "specs:#{name}:private" do
run_specs("spec/private/**/*_spec.rb", spec_cmd, ENV['RSPEC_OPTS'] || run_opts)
end
desc "Run public specs (#{name})"
task "specs:#{name}:public" do
run_specs("spec/public/**/*_spec.rb", spec_cmd, ENV['RSPEC_OPTS'] || run_opts)
end
# With profiling formatter
desc "Run all specs (#{name}) with profiling formatter"
task "specs:#{name}_profiled" do
run_specs("spec/**/*_spec.rb", spec_cmd, "-c -f o")
end
desc "Run private specs (#{name}) with profiling formatter"
task "specs:#{name}_profiled:private" do
run_specs("spec/private/**/*_spec.rb", spec_cmd, "-c -f o")
end
desc "Run public specs (#{name}) with profiling formatter"
task "specs:#{name}_profiled:public" do
run_specs("spec/public/**/*_spec.rb", spec_cmd, "-c -f o")
end
end
setup_specs("mri", "spec")
setup_specs("jruby", "jruby -S spec")
task "specs" => ["specs:mri"]
task "specs:private" => ["specs:mri:private"]
task "specs:public" => ["specs:mri:public"]
desc "Run coverage suite"
task :rcov do
require 'fileutils'
FileUtils.rm_rf("coverage") if File.directory?("coverage")
FileUtils.mkdir("coverage")
path = File.expand_path(Dir.pwd)
files = Dir["spec/**/*_spec.rb"]
files.each do |spec|
puts "Getting coverage for #{File.expand_path(spec)}"
command = %{rcov #{File.expand_path(spec)} --aggregate #{path}/coverage/data.data --exclude ".*" --include-file "lib/merb-core(?!\/vendor)"}
command += " --no-html" unless spec == files.last
`#{command} 2>&1`
end
end
desc "Run a specific spec with TASK=xxxx"
Spec::Rake::SpecTask.new("spec") do |t|
t.spec_opts = ["--format", "specdoc", "--colour"]
t.libs = ["lib", "server/lib" ]
t.spec_files = (ENV["TASK"] || '').split(',').map do |task|
"spec/**/#{task}_spec.rb"
end
end
desc "Run all specs output html"
Spec::Rake::SpecTask.new("specs_html") do |t|
t.spec_opts = ["--format", "html"]
t.libs = ["lib", "server/lib" ]
t.spec_files = Dir["spec/**/*_spec.rb"].sort
end
# desc "RCov"
# Spec::Rake::SpecTask.new("rcov") do |t|
# t.rcov_opts = ["--exclude", "gems", "--exclude", "spec"]
# t.spec_opts = ["--format", "specdoc", "--colour"]
# t.spec_files = Dir["spec/**/*_spec.rb"].sort
# t.libs = ["lib", "server/lib"]
# t.rcov = true
# end
STATS_DIRECTORIES = [
['Code', 'lib/'],
['Unit tests', 'spec']
].collect { |name, dir| [ name, "./#{dir}" ] }.
select { |name, dir| File.directory?(dir) }
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
require __DIR__ + "/tools/code_statistics"
# require "extra/stats"
verbose = true
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end
##############################################################################
# SYNTAX CHECKING
##############################################################################
task :check_syntax do
`find . -name "*.rb" |xargs -n1 ruby -c |grep -v "Syntax OK"`
puts "* Done"
end
##############################################################################
# SVN
##############################################################################
namespace :repo do
desc "Add new files to repository"
task :add do
if File.directory?(".git")
system "git add *"
elsif File.directory?(".svn")
system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
end
end
desc "Fetch changes from master repository"
task :rebase do
if File.directory?(".git")
system "git stash ; git svn rebase ; git stash apply"
elsif File.directory?(".svn")
system "svn update"
end
end
desc "commit modified changes to the repository"
task :commit do
if File.directory?(".git")
system "git commit"
elsif File.directory?(".svn")
system "svn commit"
end
end
end
# Run specific tests or test files. Searches nested spec directories as well.
#
# Based on a technique popularized by Geoffrey Grosenbach
rule "" do |t|
spec_cmd = (RUBY_PLATFORM =~ /java/) ? "jruby -S spec" : "spec"
# spec:spec_file:spec_name
if /spec:(.*)$/.match(t.name)
arguments = t.name.split(':')
file_name = arguments[1]
spec_name = arguments[2..-1]
spec_filename = "#{file_name}_spec.rb"
specs = Dir["spec/**/#{spec_filename}"]
if path = specs.detect { |f| spec_filename == File.basename(f) }
run_file_name = path
else
puts "No specs found for #{t.name.inspect}"
exit
end
example = " -e '#{spec_name}'" unless spec_name.empty?
sh "#{spec_cmd} #{run_file_name} --format specdoc --colour #{example}"
end
end
##############################################################################
# Flog
##############################################################################
namespace :flog do
task :worst_methods do
require "flog"
flogger = Flog.new
flogger.flog_files Dir["lib/**/*.rb"]
totals = flogger.totals.sort_by {|k,v| v}.reverse[0..10]
totals.each do |meth, total|
puts "%50s: %s" % [meth, total]
end
end
task :total do
require "flog"
flogger = Flog.new
flogger.flog_files Dir["lib/**/*.rb"]
puts "Total: #{flogger.total}"
end
task :per_method do
require "flog"
flogger = Flog.new
flogger.flog_files Dir["lib/**/*.rb"]
methods = flogger.totals.reject { |k,v| k =~ /\#none$/ }.sort_by { |k,v| v }
puts "Total Flog: #{flogger.total}"
puts "Total Methods: #{flogger.totals.size}"
puts "Flog / Method: #{flogger.total / methods.size}"
end
end
namespace :tools do
namespace :tags do
desc "Generates Emacs tags using Exuberant Ctags."
task :emacs do
sh "ctags -e --Ruby-kinds=-f -o TAGS -R lib"
end
end
end
require File.join(File.dirname(__FILE__), "..", "lib", "merb-core")
module Merb
class Responder
def self.parse(accept_header)
list = accept_header.to_s.split(/,/).enum_for(:each_with_index).map do |entry,index|
AcceptType.new(entry,index += 1)
end.sort.uniq
# firefox (and possibly other browsers) send broken default accept headers.
# fix them up by sorting alternate xml forms (namely application/xhtml+xml)
# ahead of pure xml types (application/xml,text/xml).
if app_xml = list.detect{|e| e.super_range == 'application/xml'}
list.select{|e| e.to_s =~ /\+xml/}.each { |acc_type|
list[list.index(acc_type)],list[list.index(app_xml)] =
list[list.index(app_xml)],list[list.index(acc_type)] }
end
list
end
def self.parse_new(accept_header)
# FF2 is broken. If we get FF2 headers, use FF3 headers instead.
if accept_header == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
accept_header = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
end
headers = accept_header.split(/,/)
idx, list = 0, []
while idx < headers.size
list << AcceptType.new(headers[idx], idx)
idx += 1
end
list.sort
end
end
end
require "rubygems"
require "rbench"
RBench.run(10_000) do
report "old_parse" do
Merb::Responder.parse("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
end
report "new_parse" do
Merb::Responder.parse_new("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
end
end
require "rubygems"
require "rbench"
TYPES = {:all=>{:response_headers=>{}, :accepts=>["*/*"], :response_block=>nil, :transform_method=>nil}, :yaml=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["application/x-yaml", "text/yaml"], :response_block=>nil, :transform_method=>:to_yaml}, :text=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["text/plain"], :response_block=>nil, :transform_method=>:to_text}, :html=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["text/html", "application/xhtml+xml", "application/html"], :response_block=>nil, :transform_method=>:to_html}, :xml=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["application/xml", "text/xml", "application/x-xml"], :response_block=>nil, :transform_method=>:to_xml}, :js=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["text/javascript", "application/javascript", "application/x-javascript"], :response_block=>nil, :transform_method=>:to_json}, :json=>{:response_headers=>{:charset=>"utf-8"}, :accepts=>["application/json", "text/x-json"], :response_block=>nil, :transform_method=>:to_json}}
MIMES = {"application/json"=>:json, "application/javascript"=>:js, "text/plain"=>:text, "text/html"=>:html, "application/x-xml"=>:xml, "text/javascript"=>:js, "application/x-javascript"=>:js, "application/x-yaml"=>:yaml, "*/*"=>:all, "application/xml"=>:xml, "text/x-json"=>:json, "application/xhtml+xml"=>:html, "text/yaml"=>:yaml, "text/xml"=>:xml, "application/html"=>:html}
RBench.run(1_000_000) do
report("old way") do
TYPES.values.map {|e| e[:accepts] if e[:accepts].include?("text/html")}.compact.flatten
end
report("new way") do
TYPES[MIMES["text/html"]][:accepts]
end
end
require 'set'
require 'benchmark'
require 'forwardable'
TIMES = (ARGV[0] || 100_000).to_i
hsh = {:x => true, :y => true}
set = Set.new([:x, :y])
fst = FasterSet.new([:x, :y])
Benchmark.bmbm do |x|
x.report("current included") { TIMES.times { hsh[:x] } }
x.report("hash included") { TIMES.times { hsh.include?(:x) } }
x.report("set included") { TIMES.times { set.include?(:x) } }
x.report("fasterset included") { TIMES.times { fst.include?(:x) } }
x.report("current !included") { TIMES.times { hsh[:z] } }
x.report("hash !included") { TIMES.times { hsh.include?(:z) } }
x.report("set !included") { TIMES.times { set.include?(:z) } }
x.report("fasterset !included") { TIMES.times { fst.include?(:z) } }
end
# TIMES = 1_000_000
# user system total real
# current included 0.400000 0.000000 0.400000 ( 0.400513)
# hash included 0.390000 0.000000 0.390000 ( 0.396909)
# set included 1.060000 0.000000 1.060000 ( 1.055078)
# fasterset included 0.400000 0.000000 0.400000 ( 0.401823)
# current !included 0.510000 0.000000 0.510000 ( 0.508479)
# hash !included 0.400000 0.000000 0.400000 ( 0.400109)
# set !included 1.050000 0.010000 1.060000 ( 1.062367)
# fasterset !included 0.400000 0.000000 0.400000 ( 0.399415)
require "rubygems"
require "rbench"
SIMPLE = "text/html"
QUAL = "text/html ; q= 0.5"
RBench.run(100_000) do
column :original
column :capture
report("simple") do
original { SIMPLE.split(/;\s*q=/).map{|a| a.strip } }
capture do
SIMPLE =~ /\s*([^;\s]*)\s*(;\s*q=\s*(.*))?/
[$1, $3]
end
end
report("qual") do
original { QUAL.split(/;\s*q=/).map{|a| a.strip } }
capture do
QUAL =~ /\s*([^;\s]*)\s*(;\s*q=\s*(.*))?/
[$1, $3]
end
end
end
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("split") { TIMES.times { "aaa/aaa/aaa.bbb.ccc.ddd".split(".").last }}
x.report("match") { TIMES.times { "aaa/aaa/aaa.bbb.ccc.ddd".match(/\.([^\.]*)$/)[1] }}
end
# TIMES == 1_000_000
# user system total real
# split 4.150000 0.010000 4.160000 ( 4.155064)
# match 3.670000 0.000000 3.670000 ( 3.683401)
require 'benchmark'
TIMES = (ARGV[0] || 100_000).to_i
Benchmark.bmbm do |x|
x.report("squeeze") { TIMES.times { "abc//def//ghi//jkl".squeeze("/") }}
x.report("gsub") { TIMES.times { "abc//def//ghi//jkl".gsub(/\/+/, "/") }}
end
# TIMES == 1_000_000
# user system total real
# squeeze 1.480000 0.010000 1.490000 ( 1.491509)
# gsub 3.090000 0.010000 3.100000 ( 3.107455)
require "rubygems"
require "rbench"
RBench.run(10_000) do
report "string =~" do
"text/html, foo/bar, baz/bat" =~ %r{^text/html}
end
report "string[0..8]" do
"text/html"[0..8] == "text/html"
end
end
require "rubygems"
require "rbench"
HELLO = "Hello"
HELLO_F = "Hello".freeze
HELLO_S = "Hello".to_sym
HELLO2 = "Hello"
HELLO2_S = "Hello".to_sym
HELLO2_F = "Hello".freeze
GOODBYE = "Goodbye"
GOODBYE_F = "Goodbye".freeze
GOODBYE_S = "Goodbye".to_sym
RBench.run(1_000_000) do
column :eql
column :eql_eql
group "Same" do
report "Regular" do
eql {HELLO.eql? HELLO2}
eql_eql {HELLO == HELLO2}
end
report "Frozen" do
eql {HELLO_F.eql? HELLO2_F}
eql_eql {HELLO_F == HELLO2_F}
end
report "Symbol" do
eql {HELLO_S.eql? HELLO2_S}
eql_eql {HELLO_S == HELLO2_S}
end
end
group "Different" do
report "Regular" do
eql {HELLO.eql? GOODBYE}
eql_eql {HELLO == GOODBYE}
end
report "Frozen" do
eql {HELLO_F.eql? GOODBYE_F}
eql_eql {HELLO_F == GOODBYE_F}
end
report "Symbol" do
eql {HELLO_S.eql? GOODBYE_S}
eql_eql {HELLO_S == GOODBYE_S}
end
end
end
# EQL | EQL_EQL |
# --Same-------------------------------
# Regular 0.633 | 0.632 |
# Frozen 0.625 | 0.631 |
# Symbol 0.602 | 0.597 |
# --Different--------------------------
# Regular 0.616 | 0.612 |
# Frozen 0.623 | 0.602 |
# Symbol 0.600 | 0.608 |
if ENV["TM_RUBY"]
module Autotest::HtmlConsole
MAX = 30
STATUS = {}
OUT_DUP = STDOUT.dup
require 'stringio'
# $stdout = StringIO.new
# $stderr = StringIO.new
OUT_DUP.puts <<-HERE
<html>
<head>
<title>AutoTest Results</title>
<script>document.body.innerHTML = ''</script>
</head>
<body>
</body>
</html>
HERE
def self.update(failures = nil)
STATUS.delete STATUS.keys.sort.last if STATUS.size > MAX
STATUS.sort.reverse.each do |t,s|
if s > 0 then
OUT_DUP.puts "<p style=\"color:red\">#{t}: #{failures.join("<br/>")}</p>"
else
OUT_DUP.puts "<p style=\"color:green\">#{t}: #{s}</p>"
end
end
OUT_DUP.flush
end
Autotest.add_hook :red do |at|
STATUS[Time.now] = at.files_to_test.size
update(at.failures)
end
Autotest.add_hook :green do |at|
STATUS[Time.now] = 0
update
end
end
end
require "rubygems"
require "rbench"
def caught
catch(:halt) { yield }
end
def child
redirect(url)
end
def redirect(url)
throw(:halt, ...)
end
def returned
return yield
end
def return_redirect(url)
return ...
end
def return_child
return "Hello"
end
RBench.run(1_000_000) do
report("catch") do
caught { child }
end
report("returned") do
returned { return_child }
end
report("catch with return") do
caught { "Hello" }
end
end
require "benchmark"
class Symbol
def to_proc
lambda { |value| value.send(self) }
end
end
class Array
def map_on(sym)
self.map {|x| x.send(sym)}
end
end
small_arr = [0,1,2,3,4]
large_arr = (0...2_000).to_a
TIMES = ARGV[0] ? ARGV[0].to_i : 10_000
Benchmark.bm(30) do |x|
x.report("Symbol#to_proc (small)") do
TIMES.times do
small_arr.map(&:nonzero?)
end
end
# x.report("Symbol#to_proc (large)") do
# TIMES.times do
# large_arr.map(&:nonzero?)
# end
# end
x.report("map_on (small)") do
TIMES.times do
small_arr.map_on(:nonzero?)
end
end
# x.report("map_on (large)") do
# TIMES.times do
# large_arr.map_on(:nonzero?)
# end
# end
x.report("raw (small)") do
TIMES.times do
small_arr.map {|y| y.nonzero?}
end
end
# x.report("raw (large)") do
# TIMES.times do
# large_arr.map {|y| y.nonzero?}
# end
# end
end
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

This file has been truncated, but you can view the full file.
#---
# require 'merb' must happen after Merb::Config is instantiated
require 'rubygems'
require 'set'
require 'fileutils'
require 'socket'
require 'pathname'
require "extlib"
__DIR__ = File.dirname(__FILE__)
$LOAD_PATH.unshift __DIR__ unless
$LOAD_PATH.include?(__DIR__) ||
$LOAD_PATH.include?(File.expand_path(__DIR__))
require 'merb-core' / 'vendor' / 'facets'
module Merb
module GlobalHelpers; end
class << self
# Merge environment settings
# Can allow you to have a "localdev" that runs like your "development"
# OR
# A "staging" environment that runs like your "production"
#
# ==== Examples
# From any environment config file (ie, development.rb, custom.rb, localdev.rb, etc)
# staging.rb:
# Merb.merge_env "production" #We want to use all the settings production uses
# Merb::Config.use { |c|
# c[:log_level] = "debug" #except we want debug log level
# c[:exception_details] = true #and we want to see exception details
# }
#
# ==== Parameters
# env<~String>:: Environment to run like
# use_db<~Boolean>:: Should Merb use the merged environments DB connection
# Defaults to +false+
def merge_env(env,use_db=false)
if Merb.environment_info.nil?
Merb.environment_info = {
:real_env => Merb.environment,
:merged_envs => [],
:db_env => Merb.environment
}
end
#Only load if it hasn't been loaded
unless Merb.environment_info[:merged_envs].member? env
Merb.environment_info[:merged_envs] << env
env_file = Merb.dir_for(:config) / "environments" / ("#{env}.rb")
if File.exists?(env_file)
load(env_file)
else
Merb.logger.warn! "Environment file does not exist! #{env_file}"
end
end
# Mark specific environment to load when ORM loads,
# if multiple environments are loaded, the last one
# with use_db as TRUE will be loaded
if use_db
Merb.environment_info[:db_env] = env
end
end
# Startup Merb by setting up the Config and starting the server.
# This is where Merb application environment and root path are set.
#
# ==== Parameters
# argv<String, Hash>::
# The config arguments to start Merb with. Defaults to +ARGV+.
def start(argv=ARGV)
if Hash === argv
Merb::Config.setup(argv)
else
Merb::Config.parse_args(argv)
end
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
case Merb::Config[:action]
when :kill
Merb::Server.kill(Merb::Config[:port], 1)
when :kill_9
Merb::Server.kill(Merb::Config[:port], 9)
else
Merb::Server.start(Merb::Config[:port], Merb::Config[:cluster])
end
end
# Start the Merb environment, but only if it hasn't been loaded yet.
#
# ==== Parameters
# argv<String, Hash>::
# The config arguments to start Merb with. Defaults to +ARGV+.
def start_environment(argv=ARGV)
unless (@started ||= false)
start(argv)
@started = true
end
end
# Restart the Merb environment explicitly.
#
# ==== Parameters
# argv<String, Hash>::
# The config arguments to restart Merb with. Defaults to +Merb::Config+.
def restart_environment(argv={})
@started = false
start_environment(Merb::Config.to_hash.merge(argv))
end
attr_accessor :environment, :load_paths, :adapter, :environment_info, :started
alias :env :environment
alias :started? :started
Merb.load_paths = Dictionary.new { [Merb.root] } unless Merb.load_paths.is_a?(Dictionary)
# This is the core mechanism for setting up your application layout.
# There are three application layouts in Merb:
#
# Regular app/:type layout of Ruby on Rails fame:
#
# app/models for models
# app/mailers for mailers (special type of controllers)
# app/parts for parts, Merb components
# app/views for templates
# app/controllers for controller
# lib for libraries
#
# Flat application layout:
#
# application.rb for models, controllers, mailers, etc
# config/init.rb for initialization and router configuration
# config/framework.rb for framework and dependencies configuration
# views for views
#
# and Camping-style "very flat" application layout, where the whole Merb
# application and configs fit into a single file.
#
# ==== Notes
# Autoloading for lib uses empty glob by default. If you
# want to have your libraries under lib use autoload, add
# the following to Merb init file:
#
# Merb.push_path(:lib, Merb.root / "lib", "**/*.rb") # glob set explicity.
#
# Then lib/magicwand/lib/magicwand.rb with MagicWand module will
# be autoloaded when you first access that constant.
#
# ==== Examples
# This method gives you a way to build up your own application
# structure, for instance, to reflect the structure Rails
# uses to simplify transition of legacy application, you can
# set it up like this:
#
# Merb.push_path(:model, Merb.root / "app" / "models", "**/*.rb")
# Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
# Merb.push_path(:controller, Merb.root / "app" / "controllers", "**/*.rb")
# Merb.push_path(:view, Merb.root / "app" / "views", "**/*.rb")
#
# ==== Parameters
# type<Symbol>:: The type of path being registered (i.e. :view)
# path<String>:: The full path
# file_glob<String>::
# A glob that will be used to autoload files under the path. Defaults to
# "**/*.rb".
def push_path(type, path, file_glob = "**/*.rb")
enforce!(type => Symbol)
load_paths[type] = [Pathname.new(path), file_glob]
end
# Removes given types of application components
# from load path Merb uses for autoloading.
#
# ==== Parameters
# *args<Array(Symbol)>::
# components names, for instance, :views, :models
#
# ==== Examples
# Using this combined with Merb::GlobalHelpers.push_path
# you can make your Merb application use legacy Rails
# application components.
#
# Merb.root = "path/to/legacy/app/root"
# Merb.remove_paths(:mailer)
# Merb.push_path(:mailer, Merb.root / "app" / "models", "**/*.rb")
#
# Will make Merb use app/models for mailers just like Ruby on Rails does.
def remove_paths(*args)
args.each {|arg| load_paths.delete(arg)}
end
# ==== Parameters
# type<Symbol>:: The type of path to retrieve directory for, e.g. :view.
#
# ==== Returns
# String:: The directory for the requested type.
def dir_for(type)
Merb.load_paths[type].first
end
# ==== Parameters
# type<Symbol>:: The type of path to retrieve glob for, e.g. :view.
#
# ===== Returns
# String:: The pattern with which to match files within the type directory.
def glob_for(type)
Merb.load_paths[type][1]
end
# ==== Returns
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment