diff --git a/lib/zoid/application.rb b/lib/zoid/application.rb index 323f796..8534362 100644 --- a/lib/zoid/application.rb +++ b/lib/zoid/application.rb @@ -3,5 +3,19 @@ module Zoid Application = StrokeDB::Meta.new do validates_presence_of :name validates_presence_of :nsurl + + def route_for(method, path) + case path + when /^\/(\w+)(\/)?$/ + app_module.const_get($1.camelize) + end + end + + private + + def app_module + @module ||= Module.find_by_nsurl(nsurl) + end + end end \ No newline at end of file diff --git a/spec/routing_spec.rb b/spec/routing_spec.rb new file mode 100644 index 0000000..0d2f0e8 --- /dev/null +++ b/spec/routing_spec.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe Zoid::Application, "router" do + + before(:each) do + setup_default_store + @module = Module.new do + nsurl 'http://strokedb.com/zoid/spec#routing' + SomeName = StrokeDB::Meta.new + end + @app = Zoid::Application.create!(:name => 'Routing Application', :nsurl => @module.nsurl) + end + + it "should route GET + /name(/)? to a named entity within application module" do + @app.route_for('GET', '/some_name').should == @module.const_get('SomeName') + @app.route_for('GET', '/some_name/').should == @module.const_get('SomeName') + end + +end \ No newline at end of file diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..2144705 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,7 @@ +--colour +--format +progress +--loadby +mtime +--reverse +--backtrace \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..defd629 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,11 @@ +$LOAD_PATH.unshift( File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) ).uniq! +require 'zoid' + +SPEC_ROOT = File.expand_path(File.dirname(__FILE__)) +TEMP_DIR = SPEC_ROOT + '/tmp' +TEMP_STORAGES = TEMP_DIR + '/storages' + +def setup_default_store + FileUtils.rm_rf TEMP_STORAGES + '/spec' + StrokeDB::Config.build :default => true, :base_path => TEMP_STORAGES + '/spec' +end \ No newline at end of file