Permalink
Browse files

Experimenting

  • Loading branch information...
jmazzi committed Dec 9, 2011
1 parent 34da719 commit c9c2d4ef0b1cb73e2c97504e5ec7e7e4985e320a
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -61,6 +61,16 @@ module Domain
module Domain
class Enom
+ include Rainman::Handler
+ attr_reader
+
+ def initialize
+ @config =
+ end
+
+ def register(opts = {})
+
+ end
end
end
View
@@ -1,5 +1,21 @@
require "rainman/version"
+require 'active_support/core_ext/string'
module Rainman
- # Your code goes here...
+ autoload :Driver, 'rainman/driver'
+ autoload :Handler, 'rainman/handler'
+
+ class << self
+ def load_strategy(strategy = nil)
+ if strategy
+ if [:require, :autoload].include?(strategy)
+ @load_strategy = strategy
+ else
+ raise ":#{strategy} is not a recognized strategy"
+ end
+ else
+ @load_strategy ||= :autoload
+ end
+ end
+ end
end
View
@@ -0,0 +1,16 @@
+module Rainman
+ module Driver
+ extend self
+
+ def register_handler(name, &block)
+ name = name.to_s
+ klass = "#{self.name}::#{name.to_s.camelize}"
+ if self::const_defined?(name.camelize)
+ k = klass.constantize.extend(Rainman::Handler)
+ yield k.config if block_given?
+ else
+ raise "Unknown handler '#{self}::#{name.camelize}'"
+ end
+ end
+ end
+end
View
@@ -0,0 +1,9 @@
+module Rainman
+ module Handler
+ extend self
+
+ def config
+ @config ||= {}
+ end
+ end
+end
View
@@ -14,4 +14,9 @@ Gem::Specification.new do |gem|
gem.name = "rainman"
gem.require_paths = ["lib"]
gem.version = Rainman::VERSION
+
+ gem.add_development_dependency 'rspec'
+ gem.add_development_dependency 'autotest-standalone'
+ gem.add_dependency 'activesupport', '~>3.1.3'
+ gem.add_dependency 'i18n', '~>0.6.0'
end
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe Rainman::Driver do
+ describe "#register_handler" do
+
+ module Mod1
+ extend Rainman::Driver
+ class Vern
+ end
+
+ class Uhoh
+ end
+
+ register_handler(:vern)
+ register_handler(:uhoh) do |config|
+ config[:hot] = true
+ end
+ end
+
+
+ it "should make Mod1 a Driver" do
+ Mod1.should be_a(Rainman::Driver)
+ Mod1.should_not be_a(Rainman::Handler)
+ end
+
+ it "should make Mod1::Vern a Handler" do
+ Mod1::Vern.should be_a(Rainman::Handler)
+ Mod1::Vern.should_not be_a(Rainman::Driver)
+ end
+
+ it "should raise an error for an unknow Handler" do
+ expect do
+ module Mod2
+ extend Rainman::Driver
+ register_handler(:what)
+ end
+ end.to raise_error("Unknown handler 'Mod2::What'")
+ end
+
+ it "should yield a config" do
+ Mod1::Vern.config.should eql({})
+ Mod1::Uhoh.config.should eql({ :hot => true})
+ end
+ end
+end
@@ -0,0 +1,8 @@
+require 'spec_helper'
+
+describe Rainman::Handler do
+ describe "#config" do
+ subject { Rainman::Handler.config }
+ it { should be_a(Hash) }
+ end
+end
View
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe Rainman do
+ before(:each) do
+ Rainman.instance_variable_set('@load_strategy', nil)
+ end
+
+ describe "#load_strategy" do
+ its(:load_strategy) { should eql(:autoload) }
+
+ it "should set the load_strategy" do
+ Rainman.load_strategy :require
+ Rainman.load_strategy.should eql(:require)
+
+ Rainman.load_strategy :autoload
+ Rainman.load_strategy.should eql(:autoload)
+ end
+
+ it "should raise an error on invalid strategy" do
+ expect {
+ Rainman.load_strategy :invalid
+ }.to raise_error(':invalid is not a recognized strategy')
+ end
+ end
+end
View
@@ -0,0 +1 @@
+require 'rainman'

0 comments on commit c9c2d4e

Please sign in to comment.