Permalink
Browse files

improved Api inclusion

  • Loading branch information...
kristianmandrup committed Jun 13, 2011
1 parent 5bd8cb3 commit defb300854e1175a2632180fcc23b27ae0d10c64
View
@@ -2,7 +2,9 @@ source "http://rubygems.org"
gem "require_all", "~> 1.2.0"
gem "sugar-high", "~> 0.4.6.3"
-gem "geo_units"
+gem "geo_units"
+gem 'i18n'
+gem 'activesupport', '>= 3.0.1'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
@@ -1 +1 @@
-0.7.2
+0.7.3
View
@@ -1,8 +1,8 @@
require 'geo_units'
require 'sugar-high/math'
+require 'geo_calc/calc'
-module GeoCalc
- autoload :Calc, 'geo_calc/calc'
+module GeoCalc
autoload :PrettyPrint, 'geo_calc/pretty_print'
end
View
@@ -1,22 +1,20 @@
+require 'active_support/inflector'
+
module GeoCalc
- module Calc
- autoload :Bearing, 'geo_calc/calc/bearing'
- autoload :Destination, 'geo_calc/calc/destination'
- autoload :Distance, 'geo_calc/calc/distance'
- autoload :Intersection, 'geo_calc/calc/intersection'
- autoload :Midpoint, 'geo_calc/calc/midpoint'
- autoload :Rhumb, 'geo_calc/calc/rhumb'
+ autoload :Bearing, 'geo_calc/calc/bearing'
+ autoload :Destination, 'geo_calc/calc/destination'
+ autoload :Distance, 'geo_calc/calc/distance'
+ autoload :Intersection, 'geo_calc/calc/intersection'
+ autoload :Midpoint, 'geo_calc/calc/midpoint'
+ autoload :Rhumb, 'geo_calc/calc/rhumb'
- module All
- def self.included base
- base.send :include, GeoCalc::Calc::Bearing
- base.send :include, GeoCalc::Calc::Destination
- base.send :include, GeoCalc::Calc::Distance
- base.send :include, GeoCalc::Calc::Intersection
- base.send :include, GeoCalc::Calc::Midpoint
- base.send :include, GeoCalc::Calc::Rhumb
- base.send :include, GeoCalc::PrettyPrint
- end
- end
+ def self.included base
+ apis.each do |api|
+ base.send :include, "GeoCalc::#{api}".constantize
+ end
+ end
+
+ def self.apis
+ [:Bearing, :Destination, :Distance, :Intersection, :Midpoint, :Rhumb]
end
end
@@ -1,4 +1,4 @@
-module GeoCalc::Calc
+module GeoCalc
module Bearing
def bearing_to point
GeoCalc::Calc::Bearing.bearing_to self, point
@@ -1,4 +1,4 @@
-module GeoCalc::Calc
+module GeoCalc
module Destination
def destination_point brng, dist
GeoCalc::Calc::Destination.destination_point self, brng, dist
@@ -3,7 +3,7 @@
# - www.movable-type.co.uk/scripts/latlong.html
#
-module GeoCalc::Calc
+module GeoCalc
module Distance
def distance_to point, precision = 4
GeoCalc::Calc::Distance.distance_to self, point, precision
@@ -1,4 +1,4 @@
-module GeoCalc::Calc
+module GeoCalc
module Midpoint
def midpoint_to point
GeoCalc::Calc::Midpoint.midpoint_to self, point
@@ -1,4 +1,4 @@
-module GeoCalc::Calc
+module GeoCalc
module Rhumb
# Returns the distance from this point to the supplied point, in km, travelling along a rhumb line
#
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+class CalcApis
+ include GeoCalc
+end
+
+class CalcDistance
+ include GeoCalc::Distance
+end
+
+
+
+# - www.movable-type.co.uk/scripts/latlong.html
+describe GeoPoint do
+ describe 'include all Apis' do
+ it 'should have Bearing api' do
+ CalcApis.new.should respond_to :bearing_to
+ end
+ end
+
+ describe 'include select Apis' do
+ it 'should not have Bearing api' do
+ dist = CalcDistance.new
+ dist.should_not respond_to :bearing_to
+ end
+
+ it 'should have Distance api' do
+ dist = CalcDistance.new
+ dist.should respond_to :distance_to
+ end
+ end
+end

0 comments on commit defb300

Please sign in to comment.