Permalink
Browse files

Pre-github

  • Loading branch information...
methodmissing committed Jan 30, 2009
0 parents commit 951c1eb51c100cded1038ad4d2ba9dbc18e44aa6
Showing with 1,721 additions and 0 deletions.
  1. 0 README
  2. +19 −0 Rakefile
  3. +1 −0 init.rb
  4. +37 −0 lib/scrooge.rb
  5. +16 −0 lib/scrooge/core/string.rb
  6. +15 −0 lib/scrooge/core/symbol.rb
  7. +148 −0 lib/scrooge/framework/base.rb
  8. +72 −0 lib/scrooge/framework/rails.rb
  9. +23 −0 lib/scrooge/middleware/tracker.rb
  10. +63 −0 lib/scrooge/orm/active_record.rb
  11. +64 −0 lib/scrooge/orm/base.rb
  12. +89 −0 lib/scrooge/profile.rb
  13. +41 −0 lib/scrooge/storage/base.rb
  14. +77 −0 lib/scrooge/storage/buffer.rb
  15. +19 −0 lib/scrooge/storage/cache.rb
  16. +44 −0 lib/scrooge/storage/file_system.rb
  17. +21 −0 lib/scrooge/storage/memory.rb
  18. +62 −0 lib/scrooge/tracker/app.rb
  19. +48 −0 lib/scrooge/tracker/base.rb
  20. +43 −0 lib/scrooge/tracker/model.rb
  21. +102 −0 lib/scrooge/tracker/resource.rb
  22. +1 −0 rails/init.rb
  23. +12 −0 spec/fixtures/config/scrooge.yml
  24. +25 −0 spec/helpers/framework/rails/cache.rb
  25. +52 −0 spec/spec_helper.rb
  26. +13 −0 spec/units/scrooge/core/string_spec.rb
  27. +13 −0 spec/units/scrooge/core/symbol_spec.rb
  28. +99 −0 spec/units/scrooge/framework/base_spec.rb
  29. +41 −0 spec/units/scrooge/framework/rails_spec.rb
  30. +57 −0 spec/units/scrooge/orm/base_spec.rb
  31. +65 −0 spec/units/scrooge/profile_spec.rb
  32. +67 −0 spec/units/scrooge/storage/base_spec.rb
  33. +24 −0 spec/units/scrooge/storage/cache_spec.rb
  34. +36 −0 spec/units/scrooge/storage/file_system_spec.rb
  35. +20 −0 spec/units/scrooge/storage/memory_spec.rb
  36. +50 −0 spec/units/scrooge/tracker/app_spec.rb
  37. +21 −0 spec/units/scrooge/tracker/base_spec.rb
  38. +39 −0 spec/units/scrooge/tracker/model_spec.rb
  39. +69 −0 spec/units/scrooge/tracker/resource_spec.rb
  40. +13 −0 spec/units/scrooge_spec.rb
0 README
No changes.
@@ -0,0 +1,19 @@
+begin
+ require 'spec'
+rescue LoadError
+ require 'rubygems'
+ require 'spec'
+end
+
+require 'spec/rake/spectask'
+
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../'
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
+
+require 'scrooge'
+
+desc "Run the specs under spec"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts << "-c"
+end
@@ -0,0 +1 @@
+require 'scrooge'
@@ -0,0 +1,37 @@
+$:.unshift(File.dirname(__FILE__))
+
+require 'scrooge/core/string'
+require 'scrooge/core/symbol'
+
+module Scrooge
+ class Base
+
+ class << self
+
+ def profile
+ @@profile ||= Scrooge::Profile.new
+ end
+
+ def profile=( profile )
+ @@profile = profile
+ end
+
+ end
+
+ def profile
+ self.class.profile
+ end
+
+ end
+
+ module Middleware
+ autoload :Tracker, 'scrooge/middleware/tracker'
+ end
+
+end
+
+require 'scrooge/profile'
+require 'scrooge/storage/base'
+require 'scrooge/orm/base'
+require 'scrooge/framework/base'
+require 'scrooge/tracker/base'
@@ -0,0 +1,16 @@
+module Scrooge
+ module Core
+ module String
+
+ # Thx ActiveSupport
+ def to_const
+ self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+ end
+
+ end
+ end
+end
+
+class String
+ include Scrooge::Core::String
+end
@@ -0,0 +1,15 @@
+module Scrooge
+ module Core
+ module Symbol
+
+ def to_const
+ to_s.to_const
+ end
+
+ end
+ end
+end
+
+class Symbol
+ include Scrooge::Core::Symbol
+end
@@ -0,0 +1,148 @@
+module Scrooge
+ module Framework
+
+ # Scrooge is framework agnostic and attempts to abstract the following :
+ #
+ # * current environment
+ # * app root dir
+ # * app tmp dir
+ # * app config dir
+ # * logging
+ # * resource endpoints
+ # * caching
+ # * injecting Rack MiddleWare
+ #
+ # Framework Signatures
+ #
+ # Scrooge will attempt to determine the current active framework it's deployed with
+ # through various framework specific hooks.
+ #
+ # module Scrooge
+ # module Framework
+ # module YetAnother < Base
+ # ...
+ # signature do
+ # Object.const_defined?( "UnlikeAnyOther" )
+ # end
+ # ...
+ # end
+ # end
+ # end
+
+ autoload :Rails, 'scrooge/framework/rails'
+
+ class Base < Scrooge::Base
+ class NotImplemented < StandardError
+ end
+
+ class NoSupportedFrameworks < StandardError
+ end
+
+ class << self
+
+ @@signatures = {}
+ @@signatures[self.name] = Hash.new( [] )
+ @@frameworks = []
+
+ def signature( &block )
+ @@signatures[self.name] = signatures << block
+ end
+
+ def signatures
+ @@signatures[self.name] || []
+ end
+
+ def frameworks
+ @@frameworks
+ end
+
+ def which_framework?
+ iterate_frameworks() || raise( NoSupportedFrameworks )
+ end
+
+ def instantiate
+ Object.module_eval("::#{which_framework?()}", __FILE__, __LINE__).new
+ end
+
+ private
+
+ def inherited( subclass ) #:nodoc:
+ @@frameworks << subclass
+ end
+
+ def iterate_frameworks #:nodoc:
+ frameworks.detect do |framework|
+ framework.signatures.all?{|sig| sig.call }
+ end
+ end
+
+ end
+
+ def environment
+ raise NotImplemented
+ end
+
+ def root
+ raise NotImplemented
+ end
+
+ def tmp
+ raise NotImplemented
+ end
+
+ def config
+ raise NotImplemented
+ end
+
+ def logger
+ raise NotImplemented
+ end
+
+ def resource( app )
+ raise NotImplemented
+ end
+
+ def write_cache( key, value )
+ raise NotImplemented
+ end
+
+ def read_cache( key )
+ raise NotImplemented
+ end
+
+ def middleware( &block )
+ raise NotImplemented
+ end
+
+ def install_scope_middleware( tracker )
+ raise NotImplemented
+ end
+
+ def install_tracking_middleware
+ raise NotImplemented
+ end
+
+ def scopes
+ ensure_scopes_path do
+ Dir.entries( scopes_path ).grep(/\d{10}/)
+ end
+ end
+
+ def scopes_path
+ @profiles_path ||= File.join( config, 'scrooge', 'scopes' )
+ end
+
+ def scope_path( scope )
+ File.join( scopes_path, scope.to_s )
+ end
+
+ private
+
+ def ensure_scopes_path #:nodoc:
+ FileUtils.makedirs( scopes_path ) unless File.exist?( scopes_path )
+ yield if block_given?
+ end
+
+ end
+ end
+end
@@ -0,0 +1,72 @@
+module Scrooge
+ module Framework
+ class Rails < Base
+
+ signature do
+ defined?(RAILS_ROOT)
+ end
+
+ signature do
+ Object.const_defined?( "ActiveSupport" )
+ end
+
+ signature do
+ Object.const_defined?( "ActionController" )
+ end
+
+ def environment
+ ::Rails.env
+ end
+
+ def root
+ ::Rails.root
+ end
+
+ def tmp
+ File.join( ::Rails.root, 'tmp' )
+ end
+
+ def config
+ File.join( ::Rails.root, 'config' )
+ end
+
+ def logger
+ ::Rails.logger
+ end
+
+ def resource( app )
+ Scrooge::Tracker::Resource.new do |resource|
+ resource.controller = app.request.path_parameters['controller']
+ resource.action = app.request.path_parameters['action']
+ resource.method = app.request.method
+ resource.format = app.request.format
+ end
+ end
+
+ def read_cache( key )
+ ::Rails.cache.read( key )
+ end
+
+ def write_cache( key, value )
+ ::Rails.cache.write( key, value )
+ end
+
+ def middleware( &block )
+ ::ActionController::Dispatcher.middleware.instance_eval do
+ block.call
+ end
+ end
+
+ def install_scope_middleware( tracker )
+ tracker.resources.each do |resource|
+ tracker.middleware.each do |resource_middleware|
+ middleware do
+ use resource_middleware
+ end
+ end
+ end
+ end
+
+ end
+ end
+end
@@ -0,0 +1,23 @@
+module Scrooge
+ module Middleware
+ class Tracker < Scrooge::Base
+
+ def initialize(app, options = {})
+ @app = app
+ end
+
+ def call(env)
+ Scrooge::Profile.tracker.track( resource ) do
+ @app.call(env)
+ end
+ end
+
+ private
+
+ def resource
+ Scrooge::Profile.framework.resource( @app )
+ end
+
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 951c1eb

Please sign in to comment.