Created
September 24, 2008 20:48
-
-
Save defunkt/12667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Gem | |
def self.activate(gem, *version_requirements) | |
options = version_requirements.last.is_a?(Hash) ? version_requirements.pop : {} | |
sources = options[:sources] || [] | |
if version_requirements.empty? then | |
version_requirements = Gem::Requirement.default | |
end | |
unless gem.respond_to?(:name) and | |
gem.respond_to?(:version_requirements) then | |
gem = Gem::Dependency.new(gem, version_requirements) | |
end | |
matches = Gem.source_index.find_name(gem.name, gem.version_requirements) | |
report_activate_error(gem) if matches.empty? | |
if @loaded_specs[gem.name] then | |
# This gem is already loaded. If the currently loaded gem is not in the | |
# list of candidate gems, then we have a version conflict. | |
existing_spec = @loaded_specs[gem.name] | |
unless matches.any? { |spec| spec.version == existing_spec.version } then | |
sources_message = sources.map { |spec| spec.full_name } | |
raise Gem::Exception, | |
"can't activate #{gem} for #{sources_message.inspect}, " \ | |
"already activated #{existing_spec.full_name}" | |
end | |
return false | |
end | |
# new load | |
spec = matches.last | |
return false if spec.loaded? | |
spec.loaded = true | |
@loaded_specs[spec.name] = spec | |
# Load dependent gems first | |
spec.runtime_dependencies.each do |dep_gem| | |
activate dep_gem, :sources => [spec, *sources] | |
end | |
# bin directory must come before library directories | |
spec.require_paths.unshift spec.bindir if spec.bindir | |
require_paths = spec.require_paths.map do |path| | |
File.join spec.full_gem_path, path | |
end | |
sitelibdir = ConfigMap[:sitelibdir] | |
# gem directories must come after -I and ENV['RUBYLIB'] | |
insert_index = load_path_insert_index | |
if insert_index then | |
# gem directories must come after -I and ENV['RUBYLIB'] | |
$LOAD_PATH.insert(insert_index, *require_paths) | |
else | |
# we are probably testing in core, -I and RUBYLIB don't apply | |
$LOAD_PATH.unshift(*require_paths) | |
end | |
return true | |
end | |
end | |
# Make the app's "lib" directory a place where ruby files get "require"d from | |
$LOAD_PATH.unshift(Merb.root / "lib") | |
#monkey patch didn't work - force this | |
dependency 'merb_activerecord', '= 0.9.4' | |
# this works with my patched merb-core kernel | |
# default does not take a version arg | |
#use_orm :activerecord #, '= 0.9.4' | |
Merb::Config.use do |c| | |
c[:session_secret_key] = '6b4a97f4af2e5928b91deb954b16918e89698032' | |
c[:session_store] = :activerecord | |
# two hours | |
c[:session_expiry] = 7200 | |
end | |
### ActiveRecord Extensions | |
# This is actually a rails plugin, but this should work | |
# Documentation is very sparse for these libs, but more info | |
# can be found here: | |
# http://rails.aizatto.com/2007/05/24/ruby-on-rails-finite-state-machine-plugin-acts_as_state_machine/ | |
# http://justbarebones.blogspot.com/2007/11/actsasstatemachine-enhancements.html | |
dependency "acts_as_state_machine" | |
dependency 'has_many_polymorphs' | |
dependency 'ar_fixtures' | |
use_test :rspec | |
require Merb.root / "config/application" | |
dependency 'merb_helpers', '= 0.9.4' | |
dependency 'merb_has_flash', '= 0.9.2' | |
dependency 'merb-mailer', '= 0.9.4' | |
dependency 'merb-haml', '= 0.9.4' | |
dependency 'merb-assets', '= 0.9.4' | |
dependency 'merb_paginate', '= 0.0.4' | |
dependency 'merb-cache', '= 0.9.4' | |
# dependency "merb-action-args" # Provides support for querystring arguments to be passed in to controller actions | |
# dependency "merb-jquery" # Provides a #jquery method to insert jQuery code in to a content block | |
# dependency "merb_param_protection" # Lets you have better control over your query string params and param logging | |
# These need to be loaded prior to loading models and | |
# controllers. | |
dependency "auth/controller" | |
dependency "auth/model" | |
dependency "auth/orm_map" | |
dependency 'spam_protection' | |
dependency 'enkoder' | |
dependency 'validatable' | |
dependency 'validatable/validates_as_email' | |
dependency 'custom_exceptions' | |
dependency 'html/tokenizer' | |
dependency 'html/sanitizer' | |
dependency 'html/node' | |
dependency 'exception_loggable' | |
dependency 'find_or_create_extensions' | |
#dependency 'json/pure' | |
#dependency 'json/add/rails' | |
#dependency 'json/add/core' | |
# Mostly adding local pathing shortcuts for Merb. | |
require Merb.root / "lib" / "merb_ext" / "merb" | |
# Load all required libs in subdirectories of lib/ | |
%w[core_ext merb_ext].each do |path| | |
$LOAD_PATH.unshift Merb.root / "lib" / path | |
Dir.glob(Merb.root / "lib" / path / "**" / "*.rb") do |file| | |
dependency file | |
end | |
end | |
# Now the application mixins | |
Dir.glob(Merb.mixins_path / "**" / "*.rb") do |file| | |
dependency file | |
end | |
Merb::BootLoader.before_app_loads do | |
### Add dependencies here that must load before the application loads: | |
ActiveRecord::Base.class_eval do | |
include ScottBarron::Acts::StateMachine | |
include FindOrCreateExtensions | |
end | |
# This is to compensate for a mismatch between the rake tasks | |
# for the db in merb_activerecord, which uses hard-coded symbols, | |
# and activerecord itself, which transforms everything to a string. | |
ActiveRecord::Base.configurations = | |
Mash.new(ActiveRecord::Base.configurations) | |
end | |
Merb::BootLoader.after_app_loads do | |
# Add our own error template, as a hack until a patch for ActiveRecordSession propagates. | |
Merb::Dispatcher::DEFAULT_ERROR_TEMPLATE = Merb.dir_for(:view) / 'exceptions/default.html' unless Merb::Dispatcher.constants.include? "DEFAULT_ERROR_TEMPLATE" | |
Role.recreate_finders | |
Application.send(:include, Merb::GlobalHelpers) | |
begin | |
require 'superredcloth' | |
rescue LoadError | |
require 'RedCloth' | |
end | |
require 'hobosupport' | |
# This gem somehow resets Array#hash, leads to an error in app load. | |
require 'bcrypt' | |
Merb::Plugins.config[:merb_cache] = { | |
:cache_html_directory => Merb.dir_for(:public) / "cache", | |
#:store => "database", | |
#:table_name => "merb_cache", | |
#:disable => "development", # disable merb-cache in development | |
#:disable => "production", | |
#:disable => true, # disable merb-cache in all environments | |
:store => "file", | |
:cache_directory => Merb.root_path("tmp/cache"), | |
#:store => "memcache", | |
#:host => "127.0.0.1:11211", | |
#:namespace => "merb_cache", | |
#:no_tracking => "false", | |
#:store => "memory", | |
# store could be: file, memcache, memory, database, dummy, ... | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment