muck-shares 0.1.8 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) hide show
  1. data/.gitignore +2 -1
  2. data/README.rdoc +7 -6
  3. data/Rakefile +5 -13
  4. data/VERSION +1 -1
  5. data/app/controllers/muck/shares_controller.rb +0 -1
  6. data/app/models/country.rb +13 -0
  7. data/app/models/language.rb +15 -0
  8. data/app/models/state.rb +13 -0
  9. data/{locales → config/locales}/ar.yml +2 -2
  10. data/{locales → config/locales}/bg.yml +2 -2
  11. data/{locales → config/locales}/ca.yml +2 -2
  12. data/{locales → config/locales}/cs.yml +2 -2
  13. data/{locales → config/locales}/da.yml +2 -2
  14. data/{locales → config/locales}/de.yml +2 -2
  15. data/{locales → config/locales}/el.yml +2 -2
  16. data/{locales → config/locales}/en.yml +2 -2
  17. data/{locales → config/locales}/es.yml +2 -2
  18. data/{locales → config/locales}/et.yml +2 -2
  19. data/{locales → config/locales}/fa.yml +2 -2
  20. data/{locales → config/locales}/fi.yml +2 -2
  21. data/{locales → config/locales}/fr.yml +2 -2
  22. data/{locales → config/locales}/gl.yml +2 -2
  23. data/{locales → config/locales}/hi.yml +2 -2
  24. data/{locales → config/locales}/hr.yml +2 -2
  25. data/{locales → config/locales}/hu.yml +2 -2
  26. data/{locales → config/locales}/id.yml +2 -2
  27. data/{locales → config/locales}/it.yml +2 -2
  28. data/{locales → config/locales}/iw.yml +2 -2
  29. data/{locales → config/locales}/ja.yml +2 -2
  30. data/{locales → config/locales}/ko.yml +2 -2
  31. data/{locales → config/locales}/lt.yml +2 -2
  32. data/{locales → config/locales}/lv.yml +2 -2
  33. data/{locales → config/locales}/mt.yml +2 -2
  34. data/{locales → config/locales}/nl.yml +2 -2
  35. data/{locales → config/locales}/no.yml +2 -2
  36. data/{locales → config/locales}/pl.yml +2 -2
  37. data/{locales → config/locales}/pt-PT.yml +2 -2
  38. data/{locales → config/locales}/ro.yml +2 -2
  39. data/{locales → config/locales}/ru.yml +2 -2
  40. data/{locales → config/locales}/sk.yml +2 -2
  41. data/{locales → config/locales}/sl.yml +2 -2
  42. data/{locales → config/locales}/sq.yml +2 -2
  43. data/{locales → config/locales}/sr.yml +2 -2
  44. data/{locales → config/locales}/sv.yml +2 -2
  45. data/config/locales/th.yml +22 -0
  46. data/{locales → config/locales}/tl.yml +2 -2
  47. data/{locales → config/locales}/tr.yml +2 -2
  48. data/{locales → config/locales}/uk.yml +2 -2
  49. data/{locales → config/locales}/vi.yml +2 -2
  50. data/{locales → config/locales}/zh-CN.yml +2 -2
  51. data/{locales → config/locales}/zh-TW.yml +3 -3
  52. data/{locales → config/locales}/zh.yml +2 -2
  53. data/config/routes.rb +9 -0
  54. data/lib/muck_shares.rb +3 -4
  55. data/lib/muck_shares/engine.rb +18 -0
  56. data/lib/muck_shares/models/share.rb +37 -0
  57. data/lib/muck_shares/models/sharer.rb +11 -0
  58. data/lib/tasks/tasks.rb +12 -0
  59. data/test/rails_test/.gitignore +8 -0
  60. data/test/rails_test/.rake_tasks +103 -0
  61. data/test/rails_test/Gemfile +45 -0
  62. data/test/rails_test/Rakefile +10 -0
  63. data/test/{rails_root → rails_test}/app/controllers/application_controller.rb +1 -1
  64. data/test/{rails_root → rails_test}/app/controllers/default_controller.rb +0 -0
  65. data/test/{rails_root → rails_test}/app/helpers/application_helper.rb +0 -0
  66. data/test/{rails_root → rails_test}/app/models/.keep +0 -0
  67. data/test/{rails_root → rails_test}/app/models/activity.rb +0 -0
  68. data/test/{rails_root → rails_test}/app/models/comment.rb +1 -1
  69. data/test/rails_test/app/models/profile.rb +3 -0
  70. data/test/{rails_root → rails_test}/app/models/share.rb +0 -0
  71. data/test/{rails_root → rails_test}/app/models/user.rb +5 -4
  72. data/test/{rails_root → rails_test}/app/models/user_session.rb +0 -0
  73. data/test/{rails_root → rails_test}/app/views/default/index.html.erb +0 -0
  74. data/test/{rails_root → rails_test}/app/views/layouts/default.html.erb +0 -0
  75. data/test/rails_test/config.ru +4 -0
  76. data/test/rails_test/config/application.rb +42 -0
  77. data/test/rails_test/config/boot.rb +13 -0
  78. data/test/rails_test/config/database.yml +16 -0
  79. data/test/rails_test/config/environment.rb +5 -0
  80. data/test/rails_test/config/environments/development.rb +26 -0
  81. data/test/rails_test/config/environments/production.rb +49 -0
  82. data/test/rails_test/config/environments/test.rb +35 -0
  83. data/test/rails_test/config/initializers/backtrace_silencers.rb +7 -0
  84. data/test/rails_test/config/initializers/geokit_config.rb +63 -0
  85. data/test/{rails_root → rails_test}/config/initializers/inflections.rb +2 -2
  86. data/test/{rails_root → rails_test}/config/initializers/mime_types.rb +0 -0
  87. data/test/rails_test/config/initializers/muck.rb +60 -0
  88. data/test/rails_test/config/initializers/secret_token.rb +7 -0
  89. data/test/rails_test/config/initializers/session_store.rb +8 -0
  90. data/test/rails_test/config/routes.rb +4 -0
  91. data/test/{rails_root → rails_test}/features/shares.feature +0 -0
  92. data/test/{rails_root → rails_test}/features/step_definitions/common_steps.rb +0 -0
  93. data/test/{rails_root → rails_test}/features/step_definitions/share_steps.rb +0 -0
  94. data/test/rails_test/features/step_definitions/web_steps.rb +219 -0
  95. data/test/rails_test/features/support/custom_env.rb +19 -0
  96. data/test/rails_test/features/support/env.rb +58 -0
  97. data/test/rails_test/features/support/paths.rb +33 -0
  98. data/test/rails_test/lib/tasks/cucumber.rake +53 -0
  99. data/test/rails_test/spec/controllers/shares_controller_spec.rb +113 -0
  100. data/test/rails_test/spec/models/share_spec.rb +55 -0
  101. data/test/rails_test/spec/models/user_spec.rb +25 -0
  102. data/test/rails_test/spec/spec_helper.rb +29 -0
  103. data/test/rails_test/vendor/plugins/geokit-rails/.gitignore +2 -0
  104. data/test/rails_test/vendor/plugins/geokit-rails/CHANGELOG.rdoc +46 -0
  105. data/test/rails_test/vendor/plugins/geokit-rails/MIT-LICENSE +20 -0
  106. data/test/rails_test/vendor/plugins/geokit-rails/README.markdown +561 -0
  107. data/test/rails_test/vendor/plugins/geokit-rails/Rakefile +18 -0
  108. data/test/rails_test/vendor/plugins/geokit-rails/about.yml +9 -0
  109. data/test/rails_test/vendor/plugins/geokit-rails/assets/api_keys_template +61 -0
  110. data/test/rails_test/vendor/plugins/geokit-rails/init.rb +1 -0
  111. data/test/rails_test/vendor/plugins/geokit-rails/install.rb +14 -0
  112. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails.rb +26 -0
  113. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
  114. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
  115. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
  116. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
  117. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
  118. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
  119. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
  120. data/test/rails_test/vendor/plugins/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
  121. data/test/rails_test/vendor/plugins/geokit-rails/test/acts_as_mappable_test.rb +474 -0
  122. data/test/rails_test/vendor/plugins/geokit-rails/test/boot.rb +25 -0
  123. data/test/rails_test/vendor/plugins/geokit-rails/test/database.yml +20 -0
  124. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/companies.yml +7 -0
  125. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/custom_locations.yml +54 -0
  126. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/locations.yml +54 -0
  127. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
  128. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/mock_families.yml +2 -0
  129. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/mock_houses.yml +9 -0
  130. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
  131. data/test/rails_test/vendor/plugins/geokit-rails/test/fixtures/mock_people.yml +5 -0
  132. data/test/{rails_root/db/.keep → rails_test/vendor/plugins/geokit-rails/test/fixtures/stores.yml} +0 -0
  133. data/test/rails_test/vendor/plugins/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
  134. data/test/rails_test/vendor/plugins/geokit-rails/test/models/company.rb +3 -0
  135. data/test/rails_test/vendor/plugins/geokit-rails/test/models/custom_location.rb +12 -0
  136. data/test/rails_test/vendor/plugins/geokit-rails/test/models/location.rb +4 -0
  137. data/test/rails_test/vendor/plugins/geokit-rails/test/models/mock_address.rb +4 -0
  138. data/test/rails_test/vendor/plugins/geokit-rails/test/models/mock_family.rb +3 -0
  139. data/test/rails_test/vendor/plugins/geokit-rails/test/models/mock_house.rb +3 -0
  140. data/test/rails_test/vendor/plugins/geokit-rails/test/models/mock_organization.rb +4 -0
  141. data/test/rails_test/vendor/plugins/geokit-rails/test/models/mock_person.rb +4 -0
  142. data/test/rails_test/vendor/plugins/geokit-rails/test/models/store.rb +3 -0
  143. data/test/rails_test/vendor/plugins/geokit-rails/test/schema.rb +60 -0
  144. data/test/rails_test/vendor/plugins/geokit-rails/test/tasks.rake +31 -0
  145. data/test/rails_test/vendor/plugins/geokit-rails/test/test_helper.rb +23 -0
  146. metadata +246 -352
  147. data/config/muck_shares_routes.rb +0 -8
  148. data/install.rb +0 -1
  149. data/lib/active_record/acts/muck_share.rb +0 -59
  150. data/lib/active_record/acts/muck_sharer.rb +0 -28
  151. data/lib/muck_shares/initialize_routes.rb +0 -8
  152. data/lib/muck_shares/tasks.rb +0 -28
  153. data/locales/th.yml +0 -22
  154. data/muck-shares.gemspec +0 -401
  155. data/rails/init.rb +0 -4
  156. data/test/rails_root/Rakefile +0 -17
  157. data/test/rails_root/app/models/profile.rb +0 -3
  158. data/test/rails_root/config/amazon_s3.yml +0 -14
  159. data/test/rails_root/config/boot.rb +0 -109
  160. data/test/rails_root/config/database.yml +0 -23
  161. data/test/rails_root/config/environment.rb +0 -33
  162. data/test/rails_root/config/environments/cucumber.rb +0 -38
  163. data/test/rails_root/config/environments/development.rb +0 -19
  164. data/test/rails_root/config/environments/production.rb +0 -1
  165. data/test/rails_root/config/environments/test.rb +0 -28
  166. data/test/rails_root/config/initializers/requires.rb +0 -13
  167. data/test/rails_root/config/initializers/session_store.rb +0 -8
  168. data/test/rails_root/config/routes.rb +0 -3
  169. data/test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb +0 -16
  170. data/test/rails_root/db/migrate/20090402033319_add_muck_activities.rb +0 -36
  171. data/test/rails_root/db/migrate/20090402234137_create_languages.rb +0 -18
  172. data/test/rails_root/db/migrate/20090426041056_create_countries.rb +0 -15
  173. data/test/rails_root/db/migrate/20090426041103_create_states.rb +0 -18
  174. data/test/rails_root/db/migrate/20090512013727_create_profiles.rb +0 -21
  175. data/test/rails_root/db/migrate/20090602041838_create_users.rb +0 -39
  176. data/test/rails_root/db/migrate/20090608073052_create_friends.rb +0 -16
  177. data/test/rails_root/db/migrate/20090613173314_create_comments.rb +0 -24
  178. data/test/rails_root/db/migrate/20090704220055_create_slugs.rb +0 -18
  179. data/test/rails_root/db/migrate/20090704220120_acts_as_taggable_on_migration.rb +0 -29
  180. data/test/rails_root/db/migrate/20090730154102_allow_null_user.rb +0 -9
  181. data/test/rails_root/db/migrate/20090803185323_create_shares.rb +0 -16
  182. data/test/rails_root/db/migrate/20090804184247_add_comment_count_to_shares.rb +0 -9
  183. data/test/rails_root/db/migrate/20090804231857_add_shares_uri_index.rb +0 -9
  184. data/test/rails_root/features/step_definitions/webrat_steps.rb +0 -128
  185. data/test/rails_root/features/support/env.rb +0 -49
  186. data/test/rails_root/features/support/paths.rb +0 -33
  187. data/test/rails_root/lib/tasks/cucumber.rake +0 -20
  188. data/test/rails_root/public/.htaccess +0 -40
  189. data/test/rails_root/public/404.html +0 -30
  190. data/test/rails_root/public/422.html +0 -30
  191. data/test/rails_root/public/500.html +0 -30
  192. data/test/rails_root/public/dispatch.rb +0 -10
  193. data/test/rails_root/public/favicon.ico +0 -0
  194. data/test/rails_root/public/images/arrow_left.gif +0 -0
  195. data/test/rails_root/public/images/arrow_right.gif +0 -0
  196. data/test/rails_root/public/images/fancybox/fancy_closebox.png +0 -0
  197. data/test/rails_root/public/images/fancybox/fancy_left.png +0 -0
  198. data/test/rails_root/public/images/fancybox/fancy_progress.png +0 -0
  199. data/test/rails_root/public/images/fancybox/fancy_right.png +0 -0
  200. data/test/rails_root/public/images/fancybox/fancy_shadow_e.png +0 -0
  201. data/test/rails_root/public/images/fancybox/fancy_shadow_n.png +0 -0
  202. data/test/rails_root/public/images/fancybox/fancy_shadow_ne.png +0 -0
  203. data/test/rails_root/public/images/fancybox/fancy_shadow_nw.png +0 -0
  204. data/test/rails_root/public/images/fancybox/fancy_shadow_s.png +0 -0
  205. data/test/rails_root/public/images/fancybox/fancy_shadow_se.png +0 -0
  206. data/test/rails_root/public/images/fancybox/fancy_shadow_sw.png +0 -0
  207. data/test/rails_root/public/images/fancybox/fancy_shadow_w.png +0 -0
  208. data/test/rails_root/public/images/fancybox/fancy_title_left.png +0 -0
  209. data/test/rails_root/public/images/fancybox/fancy_title_main.png +0 -0
  210. data/test/rails_root/public/images/fancybox/fancy_title_right.png +0 -0
  211. data/test/rails_root/public/images/icons/accept.png +0 -0
  212. data/test/rails_root/public/images/icons/add.png +0 -0
  213. data/test/rails_root/public/images/icons/delete.png +0 -0
  214. data/test/rails_root/public/images/icons/vote.png +0 -0
  215. data/test/rails_root/public/images/loading.gif +0 -0
  216. data/test/rails_root/public/images/nothing.png +0 -0
  217. data/test/rails_root/public/images/profile_default.jpg +0 -0
  218. data/test/rails_root/public/images/rails.png +0 -0
  219. data/test/rails_root/public/images/spinner.gif +0 -0
  220. data/test/rails_root/public/images/sprites.png +0 -0
  221. data/test/rails_root/public/javascripts/application.js +0 -2
  222. data/test/rails_root/public/javascripts/builder.js +0 -136
  223. data/test/rails_root/public/javascripts/controls.js +0 -963
  224. data/test/rails_root/public/javascripts/dragdrop.js +0 -972
  225. data/test/rails_root/public/javascripts/effects.js +0 -1120
  226. data/test/rails_root/public/javascripts/fancyzoom.min.js +0 -1
  227. data/test/rails_root/public/javascripts/jquery/jquery-ui.js +0 -273
  228. data/test/rails_root/public/javascripts/jquery/jquery.easing.js +0 -1
  229. data/test/rails_root/public/javascripts/jquery/jquery.fancybox.js +0 -9
  230. data/test/rails_root/public/javascripts/jquery/jquery.form.js +0 -637
  231. data/test/rails_root/public/javascripts/jquery/jquery.jgrowl.js +0 -2
  232. data/test/rails_root/public/javascripts/jquery/jquery.js +0 -19
  233. data/test/rails_root/public/javascripts/jquery/jquery.tips.js +0 -69
  234. data/test/rails_root/public/javascripts/muck.js +0 -80
  235. data/test/rails_root/public/javascripts/muck_activities.js +0 -108
  236. data/test/rails_root/public/javascripts/prototype.js +0 -4225
  237. data/test/rails_root/public/javascripts/scriptaculous.js +0 -58
  238. data/test/rails_root/public/javascripts/slider.js +0 -277
  239. data/test/rails_root/public/javascripts/sound.js +0 -60
  240. data/test/rails_root/public/robots.txt +0 -1
  241. data/test/rails_root/public/stylesheets/.keep +0 -0
  242. data/test/rails_root/public/stylesheets/admin.css +0 -12
  243. data/test/rails_root/public/stylesheets/blueprint/ie.css +0 -26
  244. data/test/rails_root/public/stylesheets/blueprint/liquid_screen.css +0 -203
  245. data/test/rails_root/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  246. data/test/rails_root/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  247. data/test/rails_root/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  248. data/test/rails_root/public/stylesheets/blueprint/plugins/buttons/readme.txt +0 -32
  249. data/test/rails_root/public/stylesheets/blueprint/plugins/buttons/screen.css +0 -97
  250. data/test/rails_root/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +0 -14
  251. data/test/rails_root/public/stylesheets/blueprint/plugins/fancy-type/screen.css +0 -71
  252. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  253. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  254. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  255. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  256. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  257. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  258. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  259. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  260. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/readme.txt +0 -18
  261. data/test/rails_root/public/stylesheets/blueprint/plugins/link-icons/screen.css +0 -40
  262. data/test/rails_root/public/stylesheets/blueprint/plugins/liquid/liquid.css +0 -134
  263. data/test/rails_root/public/stylesheets/blueprint/plugins/liquid/src/liquid.css +0 -197
  264. data/test/rails_root/public/stylesheets/blueprint/plugins/rtl/readme.txt +0 -10
  265. data/test/rails_root/public/stylesheets/blueprint/plugins/rtl/screen.css +0 -109
  266. data/test/rails_root/public/stylesheets/blueprint/print.css +0 -30
  267. data/test/rails_root/public/stylesheets/blueprint/screen.css +0 -251
  268. data/test/rails_root/public/stylesheets/blueprint/sprite.css +0 -1
  269. data/test/rails_root/public/stylesheets/blueprint/src/forms.css +0 -49
  270. data/test/rails_root/public/stylesheets/blueprint/src/grid.css +0 -213
  271. data/test/rails_root/public/stylesheets/blueprint/src/grid.png +0 -0
  272. data/test/rails_root/public/stylesheets/blueprint/src/ie.css +0 -59
  273. data/test/rails_root/public/stylesheets/blueprint/src/print.css +0 -85
  274. data/test/rails_root/public/stylesheets/blueprint/src/reset.css +0 -38
  275. data/test/rails_root/public/stylesheets/blueprint/src/typography.css +0 -105
  276. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png +0 -0
  277. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_diagonals-thick_15_444444_40x40.png +0 -0
  278. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_glass_100_f0f0f0_1x400.png +0 -0
  279. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_glass_50_99c2ff_1x400.png +0 -0
  280. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_glass_55_fbf5d0_1x400.png +0 -0
  281. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_glass_80_e6e6e6_1x400.png +0 -0
  282. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  283. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_highlight-hard_100_f9f9f9_1x100.png +0 -0
  284. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-bg_highlight-soft_100_e7eef3_1x100.png +0 -0
  285. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_222222_256x240.png +0 -0
  286. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_2694e8_256x240.png +0 -0
  287. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_2e83ff_256x240.png +0 -0
  288. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_72a7cf_256x240.png +0 -0
  289. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_888888_256x240.png +0 -0
  290. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_cd0a0a_256x240.png +0 -0
  291. data/test/rails_root/public/stylesheets/jquery/cupertino/images/ui-icons_ffffff_256x240.png +0 -0
  292. data/test/rails_root/public/stylesheets/jquery/cupertino/jquery-ui-1.7.1.custom.css +0 -404
  293. data/test/rails_root/public/stylesheets/jquery/jquery.fancybox.css +0 -44
  294. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  295. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
  296. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
  297. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
  298. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  299. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
  300. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
  301. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
  302. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_217bc0_256x240.png +0 -0
  303. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_2e83ff_256x240.png +0 -0
  304. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_469bdd_256x240.png +0 -0
  305. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_6da8d5_256x240.png +0 -0
  306. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_cd0a0a_256x240.png +0 -0
  307. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_d8e7f3_256x240.png +0 -0
  308. data/test/rails_root/public/stylesheets/jquery/redmond/images/ui-icons_f9bd01_256x240.png +0 -0
  309. data/test/rails_root/public/stylesheets/jquery/redmond/jquery-ui-1.7.1.custom.css +0 -404
  310. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  311. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  312. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  313. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  314. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  315. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  316. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  317. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  318. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-icons_222222_256x240.png +0 -0
  319. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  320. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-icons_454545_256x240.png +0 -0
  321. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-icons_888888_256x240.png +0 -0
  322. data/test/rails_root/public/stylesheets/jquery/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  323. data/test/rails_root/public/stylesheets/jquery/smoothness/jquery-ui-1.7.1.custom.css +0 -404
  324. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  325. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  326. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  327. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  328. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  329. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  330. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  331. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  332. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  333. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  334. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  335. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  336. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  337. data/test/rails_root/public/stylesheets/jquery/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  338. data/test/rails_root/public/stylesheets/jquery/ui-lightness/jquery-ui-1.7.1.custom.css +0 -404
  339. data/test/rails_root/public/stylesheets/reset.css +0 -0
  340. data/test/rails_root/public/stylesheets/styles.css +0 -89
  341. data/test/rails_root/public/stylesheets/themes/blue/styles.css +0 -1
  342. data/test/rails_root/public/stylesheets/themes/red/styles.css +0 -1
  343. data/test/rails_root/script/about +0 -3
  344. data/test/rails_root/script/breakpointer +0 -3
  345. data/test/rails_root/script/console +0 -3
  346. data/test/rails_root/script/create_project.rb +0 -52
  347. data/test/rails_root/script/cucumber +0 -8
  348. data/test/rails_root/script/dbconsole +0 -3
  349. data/test/rails_root/script/destroy +0 -3
  350. data/test/rails_root/script/generate +0 -3
  351. data/test/rails_root/script/performance/benchmarker +0 -3
  352. data/test/rails_root/script/performance/profiler +0 -3
  353. data/test/rails_root/script/performance/request +0 -3
  354. data/test/rails_root/script/plugin +0 -3
  355. data/test/rails_root/script/process/inspector +0 -3
  356. data/test/rails_root/script/process/reaper +0 -3
  357. data/test/rails_root/script/process/spawner +0 -3
  358. data/test/rails_root/script/runner +0 -3
  359. data/test/rails_root/script/server +0 -3
  360. data/test/rails_root/test/functional/.keep +0 -0
  361. data/test/rails_root/test/functional/shares_controller_test.rb +0 -119
  362. data/test/rails_root/test/test_helper.rb +0 -11
  363. data/test/rails_root/test/unit/.keep +0 -0
  364. data/test/rails_root/test/unit/share_test.rb +0 -59
  365. data/test/rails_root/test/unit/user_test.rb +0 -26
  366. data/test/rails_root/vendor/plugins/ssl_requirement/README +0 -43
  367. data/test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb +0 -62
  368. data/test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb +0 -132
  369. data/uninstall.rb +0 -1
@@ -0,0 +1,18 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ load 'test/tasks.rake'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Generate documentation for the GeoKit plugin.'
11
+ Rake::RDocTask.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'GeoKit'
14
+ rdoc.options << '--line-numbers' << '--inline-source'
15
+ rdoc.rdoc_files.include('README')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
@@ -0,0 +1,9 @@
1
+ author:
2
+ name_1: Bill Eisenhauer
3
+ homepage_1: http://blog.billeisenhauer.com
4
+ name_2: Andre Lewis
5
+ homepage_2: http://www.earthcode.com
6
+ summary: Geo distance calculations, distance calculation query support, geocoding for physical and ip addresses.
7
+ version: 1.1.4
8
+ rails_version: 1.0+
9
+ license: MIT
@@ -0,0 +1,61 @@
1
+ if defined? Geokit
2
+
3
+ # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
4
+ Geokit::default_units = :miles
5
+ Geokit::default_formula = :sphere
6
+
7
+ # This is the timeout value in seconds to be used for calls to the geocoder web
8
+ # services. For no timeout at all, comment out the setting. The timeout unit
9
+ # is in seconds.
10
+ Geokit::Geocoders::request_timeout = 3
11
+
12
+ # These settings are used if web service calls must be routed through a proxy.
13
+ # These setting can be nil if not needed, otherwise, addr and port must be
14
+ # filled in at a minimum. If the proxy requires authentication, the username
15
+ # and password can be provided as well.
16
+ Geokit::Geocoders::proxy_addr = nil
17
+ Geokit::Geocoders::proxy_port = nil
18
+ Geokit::Geocoders::proxy_user = nil
19
+ Geokit::Geocoders::proxy_pass = nil
20
+
21
+ # This is your yahoo application key for the Yahoo Geocoder.
22
+ # See http://developer.yahoo.com/faq/index.html#appid
23
+ # and http://developer.yahoo.com/maps/rest/V1/geocode.html
24
+ Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
25
+
26
+ # This is your Google Maps geocoder key.
27
+ # See http://www.google.com/apis/maps/signup.html
28
+ # and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
29
+ Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
30
+
31
+ # This is your username and password for geocoder.us.
32
+ # To use the free service, the value can be set to nil or false. For
33
+ # usage tied to an account, the value should be set to username:password.
34
+ # See http://geocoder.us
35
+ # and http://geocoder.us/user/signup
36
+ Geokit::Geocoders::geocoder_us = false
37
+
38
+ # This is your authorization key for geocoder.ca.
39
+ # To use the free service, the value can be set to nil or false. For
40
+ # usage tied to an account, set the value to the key obtained from
41
+ # Geocoder.ca.
42
+ # See http://geocoder.ca
43
+ # and http://geocoder.ca/?register=1
44
+ Geokit::Geocoders::geocoder_ca = false
45
+
46
+ # Uncomment to use a username with the Geonames geocoder
47
+ #Geokit::Geocoders::geonames="REPLACE_WITH_YOUR_GEONAMES_USERNAME"
48
+
49
+ # This is the order in which the geocoders are called in a failover scenario
50
+ # If you only want to use a single geocoder, put a single symbol in the array.
51
+ # Valid symbols are :google, :yahoo, :us, and :ca.
52
+ # Be aware that there are Terms of Use restrictions on how you can use the
53
+ # various geocoders. Make sure you read up on relevant Terms of Use for each
54
+ # geocoder you are going to use.
55
+ Geokit::Geocoders::provider_order = [:google,:us]
56
+
57
+ # The IP provider order. Valid symbols are :ip,:geo_plugin.
58
+ # As before, make sure you read up on relevant Terms of Use for each
59
+ # Geokit::Geocoders::ip_provider_order = [:geo_plugin,:ip]
60
+
61
+ end
@@ -0,0 +1 @@
1
+ require 'geokit-rails'
@@ -0,0 +1,14 @@
1
+ # Display to the console the contents of the README file.
2
+ puts IO.read(File.join(File.dirname(__FILE__), 'README.markdown'))
3
+
4
+ # place the api_keys_template in the application's /config/initializers/geokit_config.rb
5
+ path=File.expand_path(File.join(File.dirname(__FILE__), '../../../config/initializers/geokit_config.rb'))
6
+ template_path=File.join(File.dirname(__FILE__), '/assets/api_keys_template')
7
+ if File.exists?(path)
8
+ puts "It looks like you already have a configuration file at #{path}. We've left it as-is. Recommended: check #{template_path} to see if anything has changed, and update config file accordingly."
9
+ else
10
+ File.open(path, "w") do |f|
11
+ f.puts IO.read(template_path)
12
+ puts "We created a configuration file for you in config/initializers/geokit_config.rb. Add your Google API keys, etc there."
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # Load modules and classes needed to automatically mix in ActiveRecord and
2
+ # ActionController helpers. All other functionality must be explicitly
3
+ # required.
4
+ #
5
+ # Note that we don't explicitly require the geokit gem.
6
+ # You should specify gem dependencies in your config/environment.rb: config.gem "geokit"
7
+ #
8
+ if defined? Geokit
9
+ require 'geokit-rails/defaults'
10
+ require 'geokit-rails/adapters/abstract'
11
+ require 'geokit-rails/acts_as_mappable'
12
+ require 'geokit-rails/ip_geocode_lookup'
13
+
14
+ # Automatically mix in distance finder support into ActiveRecord classes.
15
+ ActiveRecord::Base.send :include, GeoKit::ActsAsMappable
16
+
17
+ # Automatically mix in ip geocoding helpers into ActionController classes.
18
+ ActionController::Base.send :include, GeoKit::IpGeocodeLookup
19
+ else
20
+ message=%q(WARNING: geokit-rails requires the Geokit gem. You either don't have the gem installed,
21
+ or you haven't told Rails to require it. If you're using a recent version of Rails:
22
+ config.gem "geokit" # in config/environment.rb
23
+ and of course install the gem: sudo gem install geokit)
24
+ puts message
25
+ Rails.logger.error message
26
+ end
@@ -0,0 +1,456 @@
1
+ module Geokit
2
+ # Contains the class method acts_as_mappable targeted to be mixed into ActiveRecord.
3
+ # When mixed in, augments find services such that they provide distance calculation
4
+ # query services. The find method accepts additional options:
5
+ #
6
+ # * :origin - can be
7
+ # 1. a two-element array of latititude/longitude -- :origin=>[37.792,-122.393]
8
+ # 2. a geocodeable string -- :origin=>'100 Spear st, San Francisco, CA'
9
+ # 3. an object which responds to lat and lng methods, or latitude and longitude methods,
10
+ # or whatever methods you have specified for lng_column_name and lat_column_name
11
+ #
12
+ # Other finder methods are provided for specific queries. These are:
13
+ #
14
+ # * find_within (alias: find_inside)
15
+ # * find_beyond (alias: find_outside)
16
+ # * find_closest (alias: find_nearest)
17
+ # * find_farthest
18
+ #
19
+ # Counter methods are available and work similarly to finders.
20
+ #
21
+ # If raw SQL is desired, the distance_sql method can be used to obtain SQL appropriate
22
+ # to use in a find_by_sql call.
23
+ module ActsAsMappable
24
+ class UnsupportedAdapter < StandardError ; end
25
+
26
+ # Mix below class methods into ActiveRecord.
27
+ def self.included(base) # :nodoc:
28
+ base.extend ClassMethods
29
+ end
30
+
31
+ # Class method to mix into active record.
32
+ module ClassMethods # :nodoc:
33
+
34
+ # Class method to bring distance query support into ActiveRecord models. By default
35
+ # uses :miles for distance units and performs calculations based upon the Haversine
36
+ # (sphere) formula. These can be changed by setting Geokit::default_units and
37
+ # Geokit::default_formula. Also, by default, uses lat, lng, and distance for respective
38
+ # column names. All of these can be overridden using the :default_units, :default_formula,
39
+ # :lat_column_name, :lng_column_name, and :distance_column_name hash keys.
40
+ #
41
+ # Can also use to auto-geocode a specific column on create. Syntax;
42
+ #
43
+ # acts_as_mappable :auto_geocode=>true
44
+ #
45
+ # By default, it tries to geocode the "address" field. Or, for more customized behavior:
46
+ #
47
+ # acts_as_mappable :auto_geocode=>{:field=>:address,:error_message=>'bad address'}
48
+ #
49
+ # In both cases, it creates a before_validation_on_create callback to geocode the given column.
50
+ # For anything more customized, we recommend you forgo the auto_geocode option
51
+ # and create your own AR callback to handle geocoding.
52
+ def acts_as_mappable(options = {})
53
+ metaclass = (class << self; self; end)
54
+
55
+ # Mix in the module, but ensure to do so just once.
56
+ return if !defined?(Geokit::Mappable) || metaclass.included_modules.include?(Geokit::ActsAsMappable::SingletonMethods)
57
+
58
+ send :extend, Geokit::ActsAsMappable::SingletonMethods
59
+ send :include, Geokit::Mappable
60
+
61
+ cattr_accessor :through
62
+ self.through = options[:through]
63
+
64
+ if reflection = Geokit::ActsAsMappable.end_of_reflection_chain(self.through, self)
65
+ metaclass.instance_eval do
66
+ [ :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name ].each do |method_name|
67
+ define_method method_name do
68
+ reflection.klass.send(method_name)
69
+ end
70
+ end
71
+ end
72
+ else
73
+ cattr_accessor :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name
74
+
75
+ self.distance_column_name = options[:distance_column_name] || 'distance'
76
+ self.default_units = options[:default_units] || Geokit::default_units
77
+ self.default_formula = options[:default_formula] || Geokit::default_formula
78
+ self.lat_column_name = options[:lat_column_name] || 'lat'
79
+ self.lng_column_name = options[:lng_column_name] || 'lng'
80
+ self.qualified_lat_column_name = "#{table_name}.#{lat_column_name}"
81
+ self.qualified_lng_column_name = "#{table_name}.#{lng_column_name}"
82
+
83
+ if options.include?(:auto_geocode) && options[:auto_geocode]
84
+ # if the form auto_geocode=>true is used, let the defaults take over by suppling an empty hash
85
+ options[:auto_geocode] = {} if options[:auto_geocode] == true
86
+ cattr_accessor :auto_geocode_field, :auto_geocode_error_message
87
+ self.auto_geocode_field = options[:auto_geocode][:field] || 'address'
88
+ self.auto_geocode_error_message = options[:auto_geocode][:error_message] || 'could not locate address'
89
+
90
+ # set the actual callback here
91
+ before_validation_on_create :auto_geocode_address
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ # this is the callback for auto_geocoding
98
+ def auto_geocode_address
99
+ address=self.send(auto_geocode_field).to_s
100
+ geo=Geokit::Geocoders::MultiGeocoder.geocode(address)
101
+
102
+ if geo.success
103
+ self.send("#{lat_column_name}=", geo.lat)
104
+ self.send("#{lng_column_name}=", geo.lng)
105
+ else
106
+ errors.add(auto_geocode_field, auto_geocode_error_message)
107
+ end
108
+
109
+ geo.success
110
+ end
111
+
112
+ def self.end_of_reflection_chain(through, klass)
113
+ while through
114
+ reflection = nil
115
+ if through.is_a?(Hash)
116
+ association, through = through.to_a.first
117
+ else
118
+ association, through = through, nil
119
+ end
120
+
121
+ if reflection = klass.reflect_on_association(association)
122
+ klass = reflection.klass
123
+ else
124
+ raise ArgumentError, "You gave #{association} in :through, but I could not find it on #{klass}."
125
+ end
126
+ end
127
+
128
+ reflection
129
+ end
130
+
131
+ # Instance methods to mix into ActiveRecord.
132
+ module SingletonMethods #:nodoc:
133
+
134
+ # A proxy to an instance of a finder adapter, inferred from the connection's adapter.
135
+ def adapter
136
+ @adapter ||= begin
137
+ require File.join(File.dirname(__FILE__), 'adapters', connection.adapter_name.downcase)
138
+ klass = Adapters.const_get(connection.adapter_name.camelcase)
139
+ klass.load(self) unless klass.loaded
140
+ klass.new(self)
141
+ rescue LoadError
142
+ raise UnsupportedAdapter, "`#{connection.adapter_name.downcase}` is not a supported adapter."
143
+ end
144
+ end
145
+
146
+ # Extends the existing find method in potentially two ways:
147
+ # - If a mappable instance exists in the options, adds a distance column.
148
+ # - If a mappable instance exists in the options and the distance column exists in the
149
+ # conditions, substitutes the distance sql for the distance column -- this saves
150
+ # having to write the gory SQL.
151
+ def find(*args)
152
+ prepare_for_find_or_count(:find, args)
153
+ super(*args)
154
+ end
155
+
156
+ # Extends the existing count method by:
157
+ # - If a mappable instance exists in the options and the distance column exists in the
158
+ # conditions, substitutes the distance sql for the distance column -- this saves
159
+ # having to write the gory SQL.
160
+ def count(*args)
161
+ prepare_for_find_or_count(:count, args)
162
+ super(*args)
163
+ end
164
+
165
+ # Finds within a distance radius.
166
+ def find_within(distance, options={})
167
+ options[:within] = distance
168
+ find(:all, options)
169
+ end
170
+ alias find_inside find_within
171
+
172
+ # Finds beyond a distance radius.
173
+ def find_beyond(distance, options={})
174
+ options[:beyond] = distance
175
+ find(:all, options)
176
+ end
177
+ alias find_outside find_beyond
178
+
179
+ # Finds according to a range. Accepts inclusive or exclusive ranges.
180
+ def find_by_range(range, options={})
181
+ options[:range] = range
182
+ find(:all, options)
183
+ end
184
+
185
+ # Finds the closest to the origin.
186
+ def find_closest(options={})
187
+ find(:nearest, options)
188
+ end
189
+ alias find_nearest find_closest
190
+
191
+ # Finds the farthest from the origin.
192
+ def find_farthest(options={})
193
+ find(:farthest, options)
194
+ end
195
+
196
+ # Finds within rectangular bounds (sw,ne).
197
+ def find_within_bounds(bounds, options={})
198
+ options[:bounds] = bounds
199
+ find(:all, options)
200
+ end
201
+
202
+ # counts within a distance radius.
203
+ def count_within(distance, options={})
204
+ options[:within] = distance
205
+ count(options)
206
+ end
207
+ alias count_inside count_within
208
+
209
+ # Counts beyond a distance radius.
210
+ def count_beyond(distance, options={})
211
+ options[:beyond] = distance
212
+ count(options)
213
+ end
214
+ alias count_outside count_beyond
215
+
216
+ # Counts according to a range. Accepts inclusive or exclusive ranges.
217
+ def count_by_range(range, options={})
218
+ options[:range] = range
219
+ count(options)
220
+ end
221
+
222
+ # Finds within rectangular bounds (sw,ne).
223
+ def count_within_bounds(bounds, options={})
224
+ options[:bounds] = bounds
225
+ count(options)
226
+ end
227
+
228
+ # Returns the distance calculation to be used as a display column or a condition. This
229
+ # is provide for anyone wanting access to the raw SQL.
230
+ def distance_sql(origin, units=default_units, formula=default_formula)
231
+ case formula
232
+ when :sphere
233
+ sql = sphere_distance_sql(origin, units)
234
+ when :flat
235
+ sql = flat_distance_sql(origin, units)
236
+ end
237
+ sql
238
+ end
239
+
240
+ private
241
+
242
+ # Prepares either a find or a count action by parsing through the options and
243
+ # conditionally adding to the select clause for finders.
244
+ def prepare_for_find_or_count(action, args)
245
+ options = args.extract_options!
246
+ #options = defined?(args.extract_options!) ? args.extract_options! : extract_options_from_args!(args)
247
+ # Obtain items affecting distance condition.
248
+ origin = extract_origin_from_options(options)
249
+ units = extract_units_from_options(options)
250
+ formula = extract_formula_from_options(options)
251
+ bounds = extract_bounds_from_options(options)
252
+
253
+ # Only proceed if this is a geokit-related query
254
+ if origin || bounds
255
+ # if no explicit bounds were given, try formulating them from the point and distance given
256
+ bounds = formulate_bounds_from_distance(options, origin, units) unless bounds
257
+ # Apply select adjustments based upon action.
258
+ add_distance_to_select(options, origin, units, formula) if origin && action == :find
259
+ # Apply the conditions for a bounding rectangle if applicable
260
+ apply_bounds_conditions(options,bounds) if bounds
261
+ # Apply distance scoping and perform substitutions.
262
+ apply_distance_scope(options)
263
+ substitute_distance_in_conditions(options, origin, units, formula) if origin && options.has_key?(:conditions)
264
+ # Order by scoping for find action.
265
+ apply_find_scope(args, options) if action == :find
266
+ # Handle :through
267
+ apply_include_for_through(options)
268
+ # Unfortunatley, we need to do extra work if you use an :include. See the method for more info.
269
+ handle_order_with_include(options,origin,units,formula) if options.include?(:include) && options.include?(:order) && origin
270
+ end
271
+
272
+ # Restore options minus the extra options that we used for the
273
+ # Geokit API.
274
+ args.push(options)
275
+ end
276
+
277
+ def apply_include_for_through(options)
278
+ if self.through
279
+ case options[:include]
280
+ when Array
281
+ options[:include] << self.through
282
+ when Hash, String, Symbol
283
+ options[:include] = [ self.through, options[:include] ]
284
+ else
285
+ options[:include] = [ self.through ]
286
+ end
287
+ end
288
+ end
289
+
290
+ # If we're here, it means that 1) an origin argument, 2) an :include, 3) an :order clause were supplied.
291
+ # Now we have to sub some SQL into the :order clause. The reason is that when you do an :include,
292
+ # ActiveRecord drops the psuedo-column (specificically, distance) which we supplied for :select.
293
+ # So, the 'distance' column isn't available for the :order clause to reference when we use :include.
294
+ def handle_order_with_include(options, origin, units, formula)
295
+ # replace the distance_column_name with the distance sql in order clause
296
+ options[:order].sub!(distance_column_name, distance_sql(origin, units, formula))
297
+ end
298
+
299
+ # Looks for mapping-specific tokens and makes appropriate translations so that the
300
+ # original finder has its expected arguments. Resets the the scope argument to
301
+ # :first and ensures the limit is set to one.
302
+ def apply_find_scope(args, options)
303
+ case args.first
304
+ when :nearest, :closest
305
+ args[0] = :first
306
+ options[:limit] = 1
307
+ options[:order] = "#{distance_column_name} ASC"
308
+ when :farthest
309
+ args[0] = :first
310
+ options[:limit] = 1
311
+ options[:order] = "#{distance_column_name} DESC"
312
+ end
313
+ end
314
+
315
+ # If it's a :within query, add a bounding box to improve performance.
316
+ # This only gets called if a :bounds argument is not otherwise supplied.
317
+ def formulate_bounds_from_distance(options, origin, units)
318
+ distance = options[:within] if options.has_key?(:within)
319
+ distance = options[:range].last-(options[:range].exclude_end?? 1 : 0) if options.has_key?(:range)
320
+ if distance
321
+ res=Geokit::Bounds.from_point_and_radius(origin,distance,:units=>units)
322
+ else
323
+ nil
324
+ end
325
+ end
326
+
327
+ # Replace :within, :beyond and :range distance tokens with the appropriate distance
328
+ # where clauses. Removes these tokens from the options hash.
329
+ def apply_distance_scope(options)
330
+ distance_condition = if options.has_key?(:within)
331
+ "#{distance_column_name} <= #{options[:within]}"
332
+ elsif options.has_key?(:beyond)
333
+ "#{distance_column_name} > #{options[:beyond]}"
334
+ elsif options.has_key?(:range)
335
+ "#{distance_column_name} >= #{options[:range].first} AND #{distance_column_name} <#{'=' unless options[:range].exclude_end?} #{options[:range].last}"
336
+ end
337
+
338
+ if distance_condition
339
+ [:within, :beyond, :range].each { |option| options.delete(option) }
340
+ options[:conditions] = merge_conditions(options[:conditions], distance_condition)
341
+ end
342
+ end
343
+
344
+ # Alters the conditions to include rectangular bounds conditions.
345
+ def apply_bounds_conditions(options,bounds)
346
+ sw,ne = bounds.sw, bounds.ne
347
+ lng_sql = bounds.crosses_meridian? ? "(#{qualified_lng_column_name}<#{ne.lng} OR #{qualified_lng_column_name}>#{sw.lng})" : "#{qualified_lng_column_name}>#{sw.lng} AND #{qualified_lng_column_name}<#{ne.lng}"
348
+ bounds_sql = "#{qualified_lat_column_name}>#{sw.lat} AND #{qualified_lat_column_name}<#{ne.lat} AND #{lng_sql}"
349
+ options[:conditions] = merge_conditions(options[:conditions], bounds_sql)
350
+ end
351
+
352
+ # Extracts the origin instance out of the options if it exists and returns
353
+ # it. If there is no origin, looks for latitude and longitude values to
354
+ # create an origin. The side-effect of the method is to remove these
355
+ # option keys from the hash.
356
+ def extract_origin_from_options(options)
357
+ origin = options.delete(:origin)
358
+ res = normalize_point_to_lat_lng(origin) if origin
359
+ res
360
+ end
361
+
362
+ # Extract the units out of the options if it exists and returns it. If
363
+ # there is no :units key, it uses the default. The side effect of the
364
+ # method is to remove the :units key from the options hash.
365
+ def extract_units_from_options(options)
366
+ units = options[:units] || default_units
367
+ options.delete(:units)
368
+ units
369
+ end
370
+
371
+ # Extract the formula out of the options if it exists and returns it. If
372
+ # there is no :formula key, it uses the default. The side effect of the
373
+ # method is to remove the :formula key from the options hash.
374
+ def extract_formula_from_options(options)
375
+ formula = options[:formula] || default_formula
376
+ options.delete(:formula)
377
+ formula
378
+ end
379
+
380
+ def extract_bounds_from_options(options)
381
+ bounds = options.delete(:bounds)
382
+ bounds = Geokit::Bounds.normalize(bounds) if bounds
383
+ end
384
+
385
+ # Geocode IP address.
386
+ def geocode_ip_address(origin)
387
+ geo_location = Geokit::Geocoders::MultiGeocoder.geocode(origin)
388
+ return geo_location if geo_location.success
389
+ raise Geokit::Geocoders::GeocodeError
390
+ end
391
+
392
+ # Given a point in a variety of (an address to geocode,
393
+ # an array of [lat,lng], or an object with appropriate lat/lng methods, an IP addres)
394
+ # this method will normalize it into a Geokit::LatLng instance. The only thing this
395
+ # method adds on top of LatLng#normalize is handling of IP addresses
396
+ def normalize_point_to_lat_lng(point)
397
+ res = geocode_ip_address(point) if point.is_a?(String) && /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/.match(point)
398
+ res = Geokit::LatLng.normalize(point) unless res
399
+ res
400
+ end
401
+
402
+ # Augments the select with the distance SQL.
403
+ def add_distance_to_select(options, origin, units=default_units, formula=default_formula)
404
+ if origin
405
+ distance_selector = distance_sql(origin, units, formula) + " AS #{distance_column_name}"
406
+ selector = options.has_key?(:select) && options[:select] ? options[:select] : "*"
407
+ options[:select] = "#{selector}, #{distance_selector}"
408
+ end
409
+ end
410
+
411
+ # Looks for the distance column and replaces it with the distance sql. If an origin was not
412
+ # passed in and the distance column exists, we leave it to be flagged as bad SQL by the database.
413
+ # Conditions are either a string or an array. In the case of an array, the first entry contains
414
+ # the condition.
415
+ def substitute_distance_in_conditions(options, origin, units=default_units, formula=default_formula)
416
+ condition = options[:conditions].is_a?(String) ? options[:conditions] : options[:conditions].first
417
+ pattern = Regexp.new("\\b#{distance_column_name}\\b")
418
+ condition.gsub!(pattern, distance_sql(origin, units, formula))
419
+ end
420
+
421
+ # Returns the distance SQL using the spherical world formula (Haversine). The SQL is tuned
422
+ # to the database in use.
423
+ def sphere_distance_sql(origin, units)
424
+ lat = deg2rad(origin.lat)
425
+ lng = deg2rad(origin.lng)
426
+ multiplier = units_sphere_multiplier(units)
427
+
428
+ adapter.sphere_distance_sql(lat, lng, multiplier) if adapter
429
+ end
430
+
431
+ # Returns the distance SQL using the flat-world formula (Phythagorean Theory). The SQL is tuned
432
+ # to the database in use.
433
+ def flat_distance_sql(origin, units)
434
+ lat_degree_units = units_per_latitude_degree(units)
435
+ lng_degree_units = units_per_longitude_degree(origin.lat, units)
436
+
437
+ adapter.flat_distance_sql(origin, lat_degree_units, lng_degree_units)
438
+ end
439
+ end
440
+ end
441
+ end
442
+
443
+ # Extend Array with a sort_by_distance method.
444
+ class Array
445
+ # This method creates a "distance" attribute on each object, calculates the
446
+ # distance from the passed origin, and finally sorts the array by the
447
+ # resulting distance.
448
+ def sort_by_distance_from(origin, opts={})
449
+ distance_attribute_name = opts.delete(:distance_attribute_name) || 'distance'
450
+ self.each do |e|
451
+ e.class.send(:attr_accessor, distance_attribute_name) if !e.respond_to?("#{distance_attribute_name}=")
452
+ e.send("#{distance_attribute_name}=", e.distance_to(origin,opts))
453
+ end
454
+ self.sort!{|a,b|a.send(distance_attribute_name) <=> b.send(distance_attribute_name)}
455
+ end
456
+ end