tournament 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/History.txt +15 -0
  2. data/Manifest.txt +241 -2
  3. data/README.txt +152 -12
  4. data/Rakefile +9 -6
  5. data/bin/benchmark_pool +0 -0
  6. data/bin/gui.rb +3 -1
  7. data/bin/picker +0 -0
  8. data/bin/pool +139 -15
  9. data/lib/tournament/bracket.rb +33 -50
  10. data/lib/tournament/entry.rb +3 -0
  11. data/lib/tournament/pool.rb +144 -93
  12. data/lib/tournament/scoring_strategy.rb +69 -0
  13. data/lib/tournament/webgui_installer.rb +109 -0
  14. data/tasks/ann.rake +19 -14
  15. data/tasks/bones.rake +6 -25
  16. data/tasks/gem.rake +46 -36
  17. data/tasks/git.rake +41 -0
  18. data/tasks/jamis.rb +589 -0
  19. data/tasks/notes.rake +28 -0
  20. data/tasks/post_load.rake +18 -11
  21. data/tasks/{doc.rake → rdoc.rake} +12 -9
  22. data/tasks/rubyforge.rake +12 -12
  23. data/tasks/setup.rb +121 -80
  24. data/tasks/spec.rake +12 -13
  25. data/tasks/svn.rake +15 -11
  26. data/tasks/test.rake +6 -6
  27. data/test/test_tournament.rb +8 -0
  28. data/test/test_webgui_installer.rb +64 -0
  29. data/webgui/README +256 -0
  30. data/webgui/Rakefile +10 -0
  31. data/webgui/app/controllers/admin_controller.rb +61 -0
  32. data/webgui/app/controllers/application.rb +25 -0
  33. data/webgui/app/controllers/entry_controller.rb +97 -0
  34. data/webgui/app/controllers/pool_controller.rb +4 -0
  35. data/webgui/app/controllers/reports_controller.rb +7 -0
  36. data/webgui/app/controllers/sessions_controller.rb +43 -0
  37. data/webgui/app/controllers/teams_controller.rb +75 -0
  38. data/webgui/app/controllers/users_controller.rb +57 -0
  39. data/webgui/app/helpers/admin_helper.rb +2 -0
  40. data/webgui/app/helpers/application_helper.rb +3 -0
  41. data/webgui/app/helpers/entry_helper.rb +2 -0
  42. data/webgui/app/helpers/pool_helper.rb +2 -0
  43. data/webgui/app/helpers/reports_helper.rb +2 -0
  44. data/webgui/app/helpers/sessions_helper.rb +2 -0
  45. data/webgui/app/helpers/teams_helper.rb +2 -0
  46. data/webgui/app/helpers/users_helper.rb +93 -0
  47. data/webgui/app/models/entry.rb +42 -0
  48. data/webgui/app/models/pool.rb +141 -0
  49. data/webgui/app/models/region.rb +3 -0
  50. data/webgui/app/models/role.rb +4 -0
  51. data/webgui/app/models/seeding.rb +4 -0
  52. data/webgui/app/models/team.rb +6 -0
  53. data/webgui/app/models/user.rb +98 -0
  54. data/webgui/app/models/user_mailer.rb +25 -0
  55. data/webgui/app/views/admin/bracket.html.erb +3 -0
  56. data/webgui/app/views/admin/entries.html.erb +25 -0
  57. data/webgui/app/views/admin/index.html.erb +17 -0
  58. data/webgui/app/views/admin/pool.html.erb +53 -0
  59. data/webgui/app/views/entry/index.html.erb +16 -0
  60. data/webgui/app/views/entry/print.erb +1 -0
  61. data/webgui/app/views/entry/print.html.erb +1 -0
  62. data/webgui/app/views/entry/show.html.erb +1 -0
  63. data/webgui/app/views/layouts/bracket.html.erb +37 -0
  64. data/webgui/app/views/layouts/default.html.erb +62 -0
  65. data/webgui/app/views/layouts/print.html.erb +12 -0
  66. data/webgui/app/views/layouts/report.html.erb +38 -0
  67. data/webgui/app/views/pool/index.html.erb +36 -0
  68. data/webgui/app/views/reports/_report.html.erb +11 -0
  69. data/webgui/app/views/reports/show.html.erb +12 -0
  70. data/webgui/app/views/sessions/new.html.erb +21 -0
  71. data/webgui/app/views/shared/_admins.html.erb +8 -0
  72. data/webgui/app/views/shared/_bracket.html.erb +1296 -0
  73. data/webgui/app/views/teams/choose.html.erb +57 -0
  74. data/webgui/app/views/user_mailer/activation.erb +3 -0
  75. data/webgui/app/views/user_mailer/signup_notification.erb +8 -0
  76. data/webgui/app/views/users/_user_bar.html.erb +8 -0
  77. data/webgui/app/views/users/new.html.erb +19 -0
  78. data/webgui/config/boot.rb +109 -0
  79. data/webgui/config/database.yml +22 -0
  80. data/webgui/config/environment.rb +78 -0
  81. data/webgui/config/environments/development.rb +29 -0
  82. data/webgui/config/environments/production.rb +24 -0
  83. data/webgui/config/environments/test.rb +22 -0
  84. data/webgui/config/initializers/inflections.rb +10 -0
  85. data/webgui/config/initializers/mime_types.rb +5 -0
  86. data/webgui/config/initializers/new_rails_defaults.rb +17 -0
  87. data/webgui/config/initializers/pool.rb +33 -0
  88. data/webgui/config/initializers/site_keys.rb +38 -0
  89. data/webgui/config/locales/en.yml +5 -0
  90. data/webgui/config/routes.rb +56 -0
  91. data/webgui/db/development.sqlite3 +0 -0
  92. data/webgui/db/migrate/20090216015836_create_entries.rb +13 -0
  93. data/webgui/db/migrate/20090217001611_add_tie_break_to_entry.rb +9 -0
  94. data/webgui/db/migrate/20090217004039_create_users.rb +23 -0
  95. data/webgui/db/migrate/20090217014940_relate_entry_and_user.rb +10 -0
  96. data/webgui/db/migrate/20090218024350_create_roles.rb +17 -0
  97. data/webgui/db/migrate/20090218024657_add_postition_to_roles.rb +9 -0
  98. data/webgui/db/migrate/20090218025240_add_admin_role.rb +10 -0
  99. data/webgui/db/migrate/20090225022928_create_pools.rb +16 -0
  100. data/webgui/db/migrate/20090225030346_associate_pool_and_entry.rb +9 -0
  101. data/webgui/db/migrate/20090225072358_change_pool_data_column.rb +9 -0
  102. data/webgui/db/migrate/20090225072849_add_completed_to_entries.rb +9 -0
  103. data/webgui/db/migrate/20090225074149_add_pool_id_index_to_entries.rb +9 -0
  104. data/webgui/db/migrate/20090225084414_add_user_id_to_pool.rb +9 -0
  105. data/webgui/db/migrate/20090226021913_add_active_to_pools.rb +9 -0
  106. data/webgui/db/migrate/20090226142240_rename_bracket_column_to_data.rb +9 -0
  107. data/webgui/db/migrate/20090301014710_create_teams.rb +84 -0
  108. data/webgui/db/migrate/20090301025902_add_more_teams.rb +16 -0
  109. data/webgui/db/migrate/20090301041526_create_seedings.rb +16 -0
  110. data/webgui/db/migrate/20090301090511_create_regions.rb +14 -0
  111. data/webgui/db/migrate/teams.txt +347 -0
  112. data/webgui/db/pool.yml +408 -0
  113. data/webgui/db/schema.rb +91 -0
  114. data/webgui/db/test.sqlite3 +0 -0
  115. data/webgui/doc/README_FOR_APP +5 -0
  116. data/webgui/lib/authenticated_system.rb +189 -0
  117. data/webgui/lib/authenticated_test_helper.rb +11 -0
  118. data/webgui/lib/form_object.rb +70 -0
  119. data/webgui/lib/pdf_helper.rb +47 -0
  120. data/webgui/lib/prince.rb +74 -0
  121. data/webgui/lib/saves_picks.rb +23 -0
  122. data/webgui/lib/tasks/admin.rake +10 -0
  123. data/webgui/public/404.html +30 -0
  124. data/webgui/public/422.html +30 -0
  125. data/webgui/public/500.html +33 -0
  126. data/webgui/public/dispatch.cgi +10 -0
  127. data/webgui/public/dispatch.fcgi +24 -0
  128. data/webgui/public/dispatch.rb +10 -0
  129. data/webgui/public/favicon.ico +0 -0
  130. data/webgui/public/images/2009FinalFour.png +0 -0
  131. data/webgui/public/images/rails.png +0 -0
  132. data/webgui/public/javascripts/application.js +2 -0
  133. data/webgui/public/javascripts/bracket.js +73 -0
  134. data/webgui/public/javascripts/controls.js +963 -0
  135. data/webgui/public/javascripts/dragdrop.js +973 -0
  136. data/webgui/public/javascripts/effects.js +1128 -0
  137. data/webgui/public/javascripts/prototype.js +4320 -0
  138. data/webgui/public/robots.txt +5 -0
  139. data/webgui/public/stylesheets/bracket-print.css +39 -0
  140. data/webgui/public/stylesheets/bracket.css +125 -0
  141. data/webgui/public/stylesheets/main.css +144 -0
  142. data/webgui/public/stylesheets/prince.css +6 -0
  143. data/webgui/public/stylesheets/prince_landscape.css +1 -0
  144. data/webgui/script/about +4 -0
  145. data/webgui/script/console +3 -0
  146. data/webgui/script/dbconsole +3 -0
  147. data/webgui/script/destroy +3 -0
  148. data/webgui/script/generate +3 -0
  149. data/webgui/script/performance/benchmarker +3 -0
  150. data/webgui/script/performance/profiler +3 -0
  151. data/webgui/script/performance/request +3 -0
  152. data/webgui/script/plugin +3 -0
  153. data/webgui/script/process/inspector +3 -0
  154. data/webgui/script/process/reaper +3 -0
  155. data/webgui/script/process/spawner +3 -0
  156. data/webgui/script/runner +3 -0
  157. data/webgui/script/server +3 -0
  158. data/webgui/test/fixtures/entries.yml +10 -0
  159. data/webgui/test/fixtures/pools.yml +14 -0
  160. data/webgui/test/fixtures/regions.yml +11 -0
  161. data/webgui/test/fixtures/roles.yml +11 -0
  162. data/webgui/test/fixtures/roles_users.yml +3 -0
  163. data/webgui/test/fixtures/seedings.yml +12 -0
  164. data/webgui/test/fixtures/teams.yml +3051 -0
  165. data/webgui/test/fixtures/users.yml +44 -0
  166. data/webgui/test/functional/admin_controller_test.rb +8 -0
  167. data/webgui/test/functional/entry_controller_test.rb +27 -0
  168. data/webgui/test/functional/pool_controller_test.rb +8 -0
  169. data/webgui/test/functional/reports_controller_test.rb +8 -0
  170. data/webgui/test/functional/sessions_controller_test.rb +82 -0
  171. data/webgui/test/functional/teams_controller_test.rb +216 -0
  172. data/webgui/test/functional/users_controller_test.rb +88 -0
  173. data/webgui/test/performance/browsing_test.rb +9 -0
  174. data/webgui/test/test_helper.rb +38 -0
  175. data/webgui/test/unit/entry_test.rb +8 -0
  176. data/webgui/test/unit/pool_test.rb +8 -0
  177. data/webgui/test/unit/region_test.rb +8 -0
  178. data/webgui/test/unit/role_test.rb +8 -0
  179. data/webgui/test/unit/seeding_test.rb +8 -0
  180. data/webgui/test/unit/team_test.rb +10 -0
  181. data/webgui/test/unit/user_mailer_test.rb +31 -0
  182. data/webgui/test/unit/user_test.rb +109 -0
  183. data/webgui/vendor/plugins/auto_complete/README +23 -0
  184. data/webgui/vendor/plugins/auto_complete/Rakefile +22 -0
  185. data/webgui/vendor/plugins/auto_complete/init.rb +2 -0
  186. data/webgui/vendor/plugins/auto_complete/lib/auto_complete.rb +47 -0
  187. data/webgui/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +143 -0
  188. data/webgui/vendor/plugins/auto_complete/test/auto_complete_test.rb +67 -0
  189. data/webgui/vendor/plugins/enumerations_mixin/ATTENTION +15 -0
  190. data/webgui/vendor/plugins/enumerations_mixin/LICENSE +20 -0
  191. data/webgui/vendor/plugins/enumerations_mixin/README_ENUMERATIONS +163 -0
  192. data/webgui/vendor/plugins/enumerations_mixin/init.rb +21 -0
  193. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/acts/enumerated.rb +177 -0
  194. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/aggregations/has_enumerated.rb +60 -0
  195. data/webgui/vendor/plugins/enumerations_mixin/lib/active_record/virtual_enumerations.rb +68 -0
  196. data/webgui/vendor/plugins/enumerations_mixin/virtual_enumerations_sample.rb +76 -0
  197. data/webgui/vendor/plugins/restful_authentication/.gitignore +21 -0
  198. data/webgui/vendor/plugins/restful_authentication/CHANGELOG +68 -0
  199. data/webgui/vendor/plugins/restful_authentication/README.textile +224 -0
  200. data/webgui/vendor/plugins/restful_authentication/Rakefile +32 -0
  201. data/webgui/vendor/plugins/restful_authentication/TODO +15 -0
  202. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/USAGE +1 -0
  203. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/authenticated_generator.rb +478 -0
  204. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/lib/insert_routes.rb +54 -0
  205. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/_model_partial.html.erb +8 -0
  206. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/activation.erb +3 -0
  207. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb +189 -0
  208. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_test_helper.rb +22 -0
  209. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/controller.rb +43 -0
  210. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/helper.rb +2 -0
  211. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/login.html.erb +16 -0
  212. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/mailer.rb +25 -0
  213. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/migration.rb +26 -0
  214. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model.rb +83 -0
  215. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_controller.rb +85 -0
  216. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper.rb +93 -0
  217. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/model_helper_spec.rb +158 -0
  218. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/observer.rb +11 -0
  219. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup.html.erb +19 -0
  220. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/signup_notification.erb +8 -0
  221. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/site_keys.rb +38 -0
  222. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/access_control_spec.rb +90 -0
  223. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/authenticated_system_spec.rb +102 -0
  224. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/sessions_controller_spec.rb +139 -0
  225. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/controllers/users_controller_spec.rb +198 -0
  226. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/fixtures/users.yml +60 -0
  227. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/helpers/users_helper_spec.rb +141 -0
  228. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/spec/models/user_spec.rb +290 -0
  229. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories.rb +22 -0
  230. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/rest_auth_stories_helper.rb +81 -0
  231. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_navigation_steps.rb +49 -0
  232. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_resource_steps.rb +179 -0
  233. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/ra_response_steps.rb +171 -0
  234. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/steps/user_steps.rb +153 -0
  235. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/accounts.story +186 -0
  236. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/stories/users/sessions.story +134 -0
  237. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/functional_test.rb +82 -0
  238. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/mailer_test.rb +31 -0
  239. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/model_functional_test.rb +93 -0
  240. data/webgui/vendor/plugins/restful_authentication/generators/authenticated/templates/test/unit_test.rb +164 -0
  241. data/webgui/vendor/plugins/restful_authentication/init.rb +1 -0
  242. data/webgui/vendor/plugins/restful_authentication/install.rb +1 -0
  243. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb +82 -0
  244. data/webgui/vendor/plugins/restful_authentication/lib/authentication/by_password.rb +64 -0
  245. data/webgui/vendor/plugins/restful_authentication/lib/authentication.rb +40 -0
  246. data/webgui/vendor/plugins/restful_authentication/lib/authorization/aasm_roles.rb +63 -0
  247. data/webgui/vendor/plugins/restful_authentication/lib/authorization/stateful_roles.rb +62 -0
  248. data/webgui/vendor/plugins/restful_authentication/lib/authorization.rb +14 -0
  249. data/webgui/vendor/plugins/restful_authentication/lib/trustification/email_validation.rb +20 -0
  250. data/webgui/vendor/plugins/restful_authentication/lib/trustification.rb +14 -0
  251. data/webgui/vendor/plugins/restful_authentication/notes/AccessControl.txt +2 -0
  252. data/webgui/vendor/plugins/restful_authentication/notes/Authentication.txt +5 -0
  253. data/webgui/vendor/plugins/restful_authentication/notes/Authorization.txt +154 -0
  254. data/webgui/vendor/plugins/restful_authentication/notes/RailsPlugins.txt +78 -0
  255. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.graffle +0 -0
  256. data/webgui/vendor/plugins/restful_authentication/notes/SecurityFramework.png +0 -0
  257. data/webgui/vendor/plugins/restful_authentication/notes/SecurityPatterns.txt +163 -0
  258. data/webgui/vendor/plugins/restful_authentication/notes/Tradeoffs.txt +126 -0
  259. data/webgui/vendor/plugins/restful_authentication/notes/Trustification.txt +49 -0
  260. data/webgui/vendor/plugins/restful_authentication/rails/init.rb +3 -0
  261. data/webgui/vendor/plugins/restful_authentication/restful-authentication.gemspec +33 -0
  262. data/webgui/vendor/plugins/restful_authentication/tasks/auth.rake +33 -0
  263. metadata +288 -8
  264. data/tasks/annotations.rake +0 -22
@@ -0,0 +1,177 @@
1
+ # Copyright (c) 2005 Trevor Squires
2
+ # Released under the MIT License. See the LICENSE file for more details.
3
+
4
+ module ActiveRecord
5
+ module Acts
6
+ module Enumerated
7
+ def self.append_features(base)
8
+ super
9
+ base.extend(MacroMethods)
10
+ end
11
+
12
+ module MacroMethods
13
+ def acts_as_enumerated(options = {})
14
+ valid_keys = [:conditions, :order, :on_lookup_failure]
15
+ options.assert_valid_keys(*valid_keys)
16
+ valid_keys.each do |key|
17
+ write_inheritable_attribute("acts_enumerated_#{key.to_s}".to_sym, options[key]) if options.has_key? key
18
+ end
19
+
20
+ unless self.is_a? ActiveRecord::Acts::Enumerated::ClassMethods
21
+ extend ActiveRecord::Acts::Enumerated::ClassMethods
22
+ class_eval do
23
+ include ActiveRecord::Acts::Enumerated::InstanceMethods
24
+ validates_uniqueness_of :name
25
+ before_save :enumeration_model_update
26
+ before_destroy :enumeration_model_update
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ module ClassMethods
33
+ attr_accessor :enumeration_model_updates_permitted
34
+
35
+ def all
36
+ return @all if @all
37
+ @all = find(:all,
38
+ :conditions => read_inheritable_attribute(:acts_enumerated_conditions),
39
+ :order => read_inheritable_attribute(:acts_enumerated_order)
40
+ ).collect{|val| val.freeze}.freeze
41
+ end
42
+
43
+ def [](arg)
44
+ case arg
45
+ when Symbol
46
+ rval = lookup_name(arg.id2name) and return rval
47
+ when String
48
+ rval = lookup_name(arg) and return rval
49
+ when Fixnum
50
+ rval = lookup_id(arg) and return rval
51
+ when nil
52
+ rval = nil
53
+ else
54
+ raise TypeError, "#{self.name}[]: argument should be a String, Symbol or Fixnum but got a: #{arg.class.name}"
55
+ end
56
+ self.send((read_inheritable_attribute(:acts_enumerated_on_lookup_failure) || :enforce_strict_literals), arg)
57
+ end
58
+
59
+ def lookup_id(arg)
60
+ all_by_id[arg]
61
+ end
62
+
63
+ def lookup_name(arg)
64
+ all_by_name[arg]
65
+ end
66
+
67
+ def include?(arg)
68
+ case arg
69
+ when Symbol
70
+ return !lookup_name(arg.id2name).nil?
71
+ when String
72
+ return !lookup_name(arg).nil?
73
+ when Fixnum
74
+ return !lookup_id(arg).nil?
75
+ when self
76
+ possible_match = lookup_id(arg.id)
77
+ return !possible_match.nil? && possible_match == arg
78
+ end
79
+ return false
80
+ end
81
+
82
+ # NOTE: purging the cache is sort of pointless because
83
+ # of the per-process rails model.
84
+ # By default this blows up noisily just in case you try to be more
85
+ # clever than rails allows.
86
+ # For those times (like in Migrations) when you really do want to
87
+ # alter the records you can silence the carping by setting
88
+ # enumeration_model_updates_permitted to true.
89
+ def purge_enumerations_cache
90
+ unless self.enumeration_model_updates_permitted
91
+ raise "#{self.name}: cache purging disabled for your protection"
92
+ end
93
+ @all = @all_by_name = @all_by_id = nil
94
+ end
95
+
96
+ private
97
+
98
+ def all_by_id
99
+ return @all_by_id if @all_by_id
100
+ @all_by_id = all.inject({}) { |memo, item| memo[item.id] = item; memo;}.freeze
101
+ end
102
+
103
+ def all_by_name
104
+ return @all_by_name if @all_by_name
105
+ begin
106
+ @all_by_name = all.inject({}) { |memo, item| memo[item.name] = item; memo;}.freeze
107
+ rescue NoMethodError => err
108
+ if err.name == :name
109
+ raise TypeError, "#{self.name}: you need to define a 'name' column in the table '#{table_name}'"
110
+ end
111
+ raise
112
+ end
113
+ end
114
+
115
+ def enforce_none(arg)
116
+ return nil
117
+ end
118
+
119
+ def enforce_strict(arg)
120
+ raise ActiveRecord::RecordNotFound, "Couldn't find a #{self.name} identified by (#{arg.inspect})"
121
+ end
122
+
123
+ def enforce_strict_literals(arg)
124
+ if Fixnum === arg || Symbol === arg
125
+ raise ActiveRecord::RecordNotFound, "Couldn't find a #{self.name} identified by (#{arg.inspect})"
126
+ end
127
+ return nil
128
+ end
129
+
130
+ end
131
+
132
+ module InstanceMethods
133
+ def ===(arg)
134
+ case arg
135
+ when Symbol, String, Fixnum, nil
136
+ return self == self.class[arg]
137
+ when Array
138
+ return self.in?(*arg)
139
+ end
140
+ super
141
+ end
142
+
143
+ alias_method :like?, :===
144
+
145
+ def in?(*list)
146
+ for item in list
147
+ self === item and return true
148
+ end
149
+ return false
150
+ end
151
+
152
+ def name_sym
153
+ self.name.to_sym
154
+ end
155
+
156
+ private
157
+
158
+ # NOTE: updating the models that back an acts_as_enumerated is
159
+ # rather dangerous because of rails' per-process model.
160
+ # The cached values could get out of synch between processes
161
+ # and rather than completely disallow changes I make you jump
162
+ # through an extra hoop just in case you're defining your enumeration
163
+ # values in Migrations. I.e. set enumeration_model_updates_permitted = true
164
+ def enumeration_model_update
165
+ if self.class.enumeration_model_updates_permitted
166
+ self.class.purge_enumerations_cache
167
+ return true
168
+ end
169
+ # Ugh. This just seems hack-ish. I wonder if there's a better way.
170
+ self.errors.add('name', "changes to acts_as_enumeration model instances are not permitted")
171
+ return false
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2005 Trevor Squires
2
+ # Released under the MIT License. See the LICENSE file for more details.
3
+
4
+ module ActiveRecord
5
+ module Aggregations # :nodoc:
6
+ module HasEnumerated # :nodoc:
7
+ def self.append_features(base)
8
+ super
9
+ base.extend(MacroMethods)
10
+ end
11
+
12
+ module MacroMethods
13
+ def has_enumerated(part_id, options = {})
14
+ options.assert_valid_keys(:class_name, :foreign_key, :on_lookup_failure)
15
+
16
+ name = part_id.id2name
17
+ class_name = (options[:class_name] || name).to_s.camelize
18
+ foreign_key = (options[:foreign_key] || "#{name}_id").to_s
19
+ failure = options[:on_lookup_failure]
20
+
21
+ module_eval <<-end_eval
22
+ def #{name}
23
+ rval = #{class_name}.lookup_id(self.#{foreign_key})
24
+ if rval.nil? && #{!failure.nil?}
25
+ return self.send(#{failure.inspect}, :read, #{name.inspect}, #{foreign_key.inspect}, #{class_name.inspect}, self.#{foreign_key})
26
+ end
27
+ return rval
28
+ end
29
+
30
+ def #{name}=(arg)
31
+ case arg
32
+ when #{class_name}
33
+ val = #{class_name}.lookup_id(arg.id)
34
+ when String
35
+ val = #{class_name}.lookup_name(arg)
36
+ when Symbol
37
+ val = #{class_name}.lookup_name(arg.id2name)
38
+ when Fixnum
39
+ val = #{class_name}.lookup_id(arg)
40
+ when nil
41
+ val = nil
42
+ else
43
+ raise TypeError, "#{self.name}: #{name}= argument must be a #{class_name}, String, Symbol or Fixnum but got a: \#{arg.class.name}"
44
+ end
45
+
46
+ if val.nil?
47
+ if #{failure.nil?}
48
+ raise ArgumentError, "#{self.name}: #{name}= can't assign a #{class_name} for a value of (\#{arg.inspect})"
49
+ end
50
+ self.send(#{failure.inspect}, :write, #{name.inspect}, #{foreign_key.inspect}, #{class_name.inspect}, arg)
51
+ else
52
+ self.#{foreign_key} = val.id
53
+ end
54
+ end
55
+ end_eval
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2005 Trevor Squires
2
+ # Released under the MIT License. See the LICENSE file for more details.
3
+
4
+ module ActiveRecord
5
+ module VirtualEnumerations # :nodoc:
6
+ class << self
7
+ def define
8
+ raise ArgumentError, "#{self.name}: must pass a block to define()" unless block_given?
9
+ config = ActiveRecord::VirtualEnumerations::Config.new
10
+ yield config
11
+ @config = config # we only overwrite config if no exceptions were thrown
12
+ end
13
+
14
+ def synthesize_if_defined(const)
15
+ options = @config[const]
16
+ return nil unless options
17
+ class_def = <<-end_eval
18
+ class #{const} < #{options[:extends]}
19
+ acts_as_enumerated :conditions => #{options[:conditions].inspect},
20
+ :order => #{options[:order].inspect},
21
+ :on_lookup_failure => #{options[:on_lookup_failure].inspect}
22
+ set_table_name(#{options[:table_name].inspect}) unless #{options[:table_name].nil?}
23
+ end
24
+ end_eval
25
+ eval(class_def, TOPLEVEL_BINDING)
26
+ rval = const_get(const)
27
+ if options[:post_synth_block]
28
+ rval.class_eval(&options[:post_synth_block])
29
+ end
30
+ return rval
31
+ end
32
+ end
33
+
34
+ class Config
35
+ def initialize
36
+ @enumeration_defs = {}
37
+ end
38
+
39
+ def define(arg, options = {}, &synth_block)
40
+ (arg.is_a?(Array) ? arg : [arg]).each do |class_name|
41
+ camel_name = class_name.to_s.camelize
42
+ raise ArgumentError, "ActiveRecord::VirtualEnumerations.define - invalid class_name argument (#{class_name.inspect})" if camel_name.blank?
43
+ raise ArgumentError, "ActiveRecord::VirtualEnumerations.define - class_name already defined (#{camel_name})" if @enumeration_defs[camel_name.to_sym]
44
+ options.assert_valid_keys(:table_name, :extends, :conditions, :order, :on_lookup_failure)
45
+ enum_def = options.clone
46
+ enum_def[:extends] ||= "ActiveRecord::Base"
47
+ enum_def[:post_synth_block] = synth_block
48
+ @enumeration_defs[camel_name.to_sym] = enum_def
49
+ end
50
+ end
51
+
52
+ def [](arg)
53
+ @enumeration_defs[arg]
54
+ end
55
+ end #class Config
56
+ end #module VirtualEnumerations
57
+ end #module ActiveRecord
58
+
59
+ class Module # :nodoc:
60
+ alias_method :enumerations_original_const_missing, :const_missing
61
+ def const_missing(const_id)
62
+ # let rails have a go at loading it
63
+ enumerations_original_const_missing(const_id)
64
+ rescue NameError
65
+ # now it's our turn
66
+ ActiveRecord::VirtualEnumerations.synthesize_if_defined(const_id) or raise
67
+ end
68
+ end
@@ -0,0 +1,76 @@
1
+ # Copyright (c) 2005 Trevor Squires
2
+ # Released under the MIT License. See the LICENSE file for more details.
3
+
4
+ # Copy this file to RAILS_ROOT/config/virtual_enumerations.rb
5
+ # and configure it accordingly.
6
+ ActiveRecord::VirtualEnumerations.define do |config|
7
+ ###
8
+ # USAGE (and don't worry, it doesn't have to be as ugly as this):
9
+ # config.define 'ClassName',
10
+ # :table_name => 'table', :extends => 'SuperclassName',
11
+ # :conditions => ['something = ?', "value"], :order => 'column ASC',
12
+ # :on_lookup_failure => :enforce_strict_literals do
13
+ # class_evaled_functions
14
+ # end
15
+ #
16
+ # 'ClassName', :table_name and :extends are used to define your virtual class.
17
+ # Note that 'ClassName' can be a :symbol or a 'CamelString'.
18
+ #
19
+ # The :conditions, :order and :on_lookup_failure arguments are passed to
20
+ # acts_as_enumerated in your virtual class. See README_ENUMERATIONS for info
21
+ # on how acts_as_enumerated works.
22
+ #
23
+ # The 'do' block will be class_eval'd by your virtual class after it has
24
+ # been loaded-on-demand.
25
+ #
26
+ ###
27
+ # Okay, that's pretty long-winded.
28
+ # Everything after the initial 'class_name' is optional so for most applications, this
29
+ # is about as verbose as you're likely to get:
30
+ #
31
+ # config.define :booking_status, :order => 'position ASC'
32
+ #
33
+ # In the above example, ActiveRecord assumes the table will be called 'booking_statuses'
34
+ # and the table should have a 'position' column defined.
35
+ #
36
+ # If you've got a bunch of enumeration classes that share the same optional parameters
37
+ # you can pass an array of names as the first argument, saving your fingers from typing
38
+ # config.define over and over again:
39
+ #
40
+ # config.define [:booking_status, :card_issuer], :order => 'position ASC'
41
+ #
42
+ # You can also take advantage of ActiveRecord's STI:
43
+ #
44
+ # config.define :enum_record, :order => 'position ASC', :table_name => 'enumrecords'
45
+ # config.define [:booking_status, :card_issuer], :extends => 'EnumRecord'
46
+ #
47
+ # In the above example, all of the records are stored in the table called 'enumrecords'
48
+ # and all acts_as_enumerated parameters are automatically inherited by the
49
+ # subclasses (although you can override them if you want).
50
+ # You can also use :extends to extend a non-virtual model class (that's already in
51
+ # your models directory) if that floats your boat.
52
+ #
53
+ # Finally, that strange optional 'do' block.
54
+ # You may be struck by the need to tamper with your virtual enumeration class after
55
+ # it has been loaded-on-demand. This can be as simple as blessing it with a
56
+ # certain 'act':
57
+ #
58
+ # config.define :enum_record, :order => 'position ASC' do
59
+ # acts_as_list # but see README_ENUMERATIONS for rules about modifying your records
60
+ # end
61
+ #
62
+ # or you may be experimenting with the dark-side... singleton methods
63
+ #
64
+ # config.define :card_issuer do
65
+ # class << self[:visa]; def verify_number(arg); some_code_here; end; end
66
+ # class << self[:master_card]; def verify_number(arg); some_other_code_here; end; end
67
+ # end
68
+ #
69
+ # For virtual enumerations, this sort of tampering *has* to be defined in the
70
+ # config.define do block. This is because in development mode, rails loads and
71
+ # subsequently clobbers your model classes for each request. The 'do' block will
72
+ # be evaluated each time your model class is loaded-on-demand.
73
+ #
74
+ ###
75
+
76
+ end
@@ -0,0 +1,21 @@
1
+ pkg
2
+ Icon?
3
+ .DS_Store
4
+ TAGS
5
+ REVISION
6
+ *.tmproj
7
+ .settings
8
+ .project
9
+ .tasks-cache
10
+ .svn
11
+ /log/*.log
12
+ /tmp/**/*
13
+ /config/database.yml
14
+ actionmailer_config_DONOTVERSION.rb
15
+ *DONOTVERSION*
16
+ /vendor/src/**/*
17
+ /db/*.sqlite*
18
+ /public/ac/*
19
+ /coverage
20
+ /doc/app
21
+ /doc/plugins
@@ -0,0 +1,68 @@
1
+ h1. Internal Changes to code
2
+
3
+ As always, this is just a copy-and-pasted version of the CHANGELOG file in the source code tree.
4
+
5
+ h2. Changes for the May, 2008 version of restful-authentication
6
+
7
+ h3. Changes to user model
8
+
9
+ * recently_activated? belongs only if stateful
10
+ * Gave migration a 40-char limit on remember_token & an index on users by login
11
+ * **Much** stricter login and email validation
12
+ * put length constraints in migration too
13
+ * password in 6, 40
14
+ * salt and remember_token now much less predictability
15
+
16
+ h3. Changes to session_controller
17
+
18
+ * use uniform logout function
19
+ * use uniform remember_cookie functions
20
+ * avoid calling logged_in? which will auto-log-you-in (safe in the face of
21
+ logout! call, but idiot-proof)
22
+ * Moved reset_session into only the "now logged in" branch
23
+ ** wherever it goes, it has to be in front of the current_user= call
24
+ ** See more in README-Tradeoffs.txt
25
+ * made a place to take action on failed login attempt
26
+ * recycle login and remember_me setting on failed login
27
+ * nil'ed out the password field in 'new' view
28
+
29
+ h3. Changes to users_controller
30
+
31
+ * use uniform logout function
32
+ * use uniform remember_cookie functions
33
+ * Moved reset_session into only the "now logged in" branch
34
+ ** wherever it goes, it has to be in front of the current_user= call
35
+ ** See more in README-Tradeoffs.txt
36
+ * made the implicit login only happen for non-activationed sites
37
+ * On a failed signup, kick you back to the signin screen (but strip out the password & confirmation)
38
+ * more descriptive error messages in activate()
39
+
40
+ h3. users_helper
41
+
42
+ * link_to_user, link_to_current_user, link_to_signin_with_IP
43
+ * if_authorized(action, resource, &block) view function (with appropriate
44
+ warning)
45
+
46
+ h3. authenticated_system
47
+
48
+ * Made authorized? take optional arguments action=nil, resource=nil, *args
49
+ This makes its signature better match traditional approaches to access control
50
+ eg Reference Monitor in "Security Patterns":http://www.securitypatterns.org/patterns.html)
51
+ * authorized? should be a helper too
52
+ * added uniform logout! methods
53
+ * format.any (as found in access_denied) doesn't work until
54
+ http://dev.rubyonrails.org/changeset/8987 lands.
55
+ * cookies are now refreshed each time we cross the logged out/in barrier, as
56
+ "best":http://palisade.plynt.com/issues/2004Jul/safe-auth-practices/
57
+ "practice":http://www.owasp.org/index.php/Session_Management#Regeneration_of_Session_Tokens
58
+
59
+ h3. Other
60
+
61
+ * Used escapes <%= %> in email templates (among other reasons, so courtenay's
62
+ "'dumbass' test":http://tinyurl.com/684g9t doesn't complain)
63
+ * Added site key to generator, users.yml.
64
+ * Made site key generation idempotent in the most crude and hackish way
65
+ * 100% coverage apart from the stateful code. (needed some access_control
66
+ checks, and the http_auth stuff)
67
+ * Stories!
68
+