merb 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/README +25 -26
  2. data/Rakefile +48 -36
  3. data/app_generators/merb/USAGE +5 -0
  4. data/app_generators/merb/merb_generator.rb +107 -0
  5. data/app_generators/merb/templates/Rakefile +99 -0
  6. data/{examples/skeleton/dist → app_generators/merb/templates}/app/controllers/application.rb +1 -1
  7. data/app_generators/merb/templates/app/controllers/exceptions.rb +13 -0
  8. data/{examples/skeleton/dist → app_generators/merb/templates}/app/helpers/global_helper.rb +0 -0
  9. data/{examples/skeleton/dist/app/mailers → app_generators/merb/templates/app/mailers/views}/layout/application.erb +0 -0
  10. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +207 -0
  11. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +38 -0
  12. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +40 -0
  13. data/app_generators/merb/templates/app/views/layout/application.html.erb +11 -0
  14. data/app_generators/merb/templates/config/boot.rb +11 -0
  15. data/app_generators/merb/templates/config/dependencies.rb +41 -0
  16. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/development.rb +0 -0
  17. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/production.rb +0 -0
  18. data/{examples/skeleton/dist/conf → app_generators/merb/templates/config}/environments/test.rb +0 -0
  19. data/app_generators/merb/templates/config/merb.yml +64 -0
  20. data/app_generators/merb/templates/config/merb_init.rb +16 -0
  21. data/app_generators/merb/templates/config/plugins.yml +1 -0
  22. data/app_generators/merb/templates/config/router.rb +32 -0
  23. data/{lib/merb/core_ext/merb_array.rb → app_generators/merb/templates/config/upload.conf} +0 -0
  24. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  25. data/app_generators/merb/templates/public/merb.fcgi +6 -0
  26. data/app_generators/merb/templates/public/stylesheets/master.css +119 -0
  27. data/app_generators/merb/templates/script/destroy +28 -0
  28. data/app_generators/merb/templates/script/generate +28 -0
  29. data/{examples/skeleton → app_generators/merb/templates}/script/stop_merb +0 -0
  30. data/app_generators/merb/templates/script/win_script.cmd +1 -0
  31. data/app_generators/merb/templates/spec/spec.opts +6 -0
  32. data/app_generators/merb/templates/spec/spec_helper.rb +10 -0
  33. data/app_generators/merb/templates/test/test_helper.rb +13 -0
  34. data/app_generators/merb_plugin/USAGE +5 -0
  35. data/app_generators/merb_plugin/merb_plugin_generator.rb +64 -0
  36. data/app_generators/merb_plugin/templates/LICENSE +20 -0
  37. data/app_generators/merb_plugin/templates/README +4 -0
  38. data/app_generators/merb_plugin/templates/Rakefile +35 -0
  39. data/app_generators/merb_plugin/templates/TODO +5 -0
  40. data/app_generators/merb_plugin/templates/merbtasks.rb +6 -0
  41. data/app_generators/merb_plugin/templates/sampleplugin.rb +10 -0
  42. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +7 -0
  43. data/app_generators/merb_plugin/templates/spec_helper.rb +2 -0
  44. data/bin/merb +1 -1
  45. data/lib/autotest/discover.rb +3 -0
  46. data/lib/autotest/merb_rspec.rb +79 -0
  47. data/lib/merb.rb +72 -93
  48. data/lib/merb/{merb_abstract_controller.rb → abstract_controller.rb} +28 -5
  49. data/lib/merb/caching/action_cache.rb +65 -29
  50. data/lib/merb/caching/fragment_cache.rb +9 -4
  51. data/lib/merb/caching/store/file_cache.rb +22 -14
  52. data/lib/merb/caching/store/memory_cache.rb +26 -8
  53. data/lib/merb/{merb_constants.rb → constants.rb} +9 -7
  54. data/lib/merb/controller.rb +178 -0
  55. data/lib/merb/core_ext.rb +13 -11
  56. data/lib/merb/core_ext/array.rb +0 -0
  57. data/lib/merb/core_ext/{merb_class.rb → class.rb} +0 -0
  58. data/lib/merb/core_ext/{merb_enumerable.rb → enumerable.rb} +0 -0
  59. data/lib/merb/core_ext/get_args.rb +52 -0
  60. data/lib/merb/core_ext/{merb_hash.rb → hash.rb} +40 -11
  61. data/lib/merb/core_ext/{merb_inflections.rb → inflections.rb} +0 -0
  62. data/lib/merb/core_ext/{merb_inflector.rb → inflector.rb} +1 -1
  63. data/lib/merb/core_ext/{merb_kernel.rb → kernel.rb} +56 -3
  64. data/lib/merb/core_ext/mash.rb +88 -0
  65. data/lib/merb/core_ext/{merb_module.rb → module.rb} +0 -0
  66. data/lib/merb/core_ext/{merb_numeric.rb → numeric.rb} +0 -0
  67. data/lib/merb/core_ext/{merb_object.rb → object.rb} +10 -47
  68. data/lib/merb/core_ext/string.rb +56 -0
  69. data/lib/merb/core_ext/{merb_symbol.rb → symbol.rb} +0 -0
  70. data/lib/merb/dispatcher.rb +109 -0
  71. data/lib/merb/{merb_drb_server.rb → drb_server.rb} +0 -0
  72. data/lib/merb/erubis_ext.rb +10 -0
  73. data/lib/merb/exceptions.rb +173 -0
  74. data/lib/merb/generators/merb_app/merb_app.rb +5 -25
  75. data/lib/merb/generators/merb_generator_helpers.rb +317 -0
  76. data/lib/merb/generators/merb_plugin.rb +19 -0
  77. data/lib/merb/logger.rb +65 -0
  78. data/lib/merb/{merb_mail_controller.rb → mail_controller.rb} +102 -49
  79. data/lib/merb/{merb_mailer.rb → mailer.rb} +31 -27
  80. data/lib/merb/mixins/{basic_authentication_mixin.rb → basic_authentication.rb} +3 -3
  81. data/lib/merb/mixins/{controller_mixin.rb → controller.rb} +131 -112
  82. data/lib/merb/mixins/{erubis_capture_mixin.rb → erubis_capture.rb} +12 -21
  83. data/lib/merb/mixins/{form_control_mixin.rb → form_control.rb} +6 -12
  84. data/lib/merb/mixins/render.rb +401 -0
  85. data/lib/merb/mixins/responder.rb +378 -0
  86. data/lib/merb/mixins/{view_context_mixin.rb → view_context.rb} +65 -10
  87. data/lib/merb/mixins/web_controller.rb +29 -0
  88. data/lib/merb/{merb_handler.rb → mongrel_handler.rb} +59 -38
  89. data/lib/merb/part_controller.rb +19 -0
  90. data/lib/merb/plugins.rb +16 -0
  91. data/lib/merb/rack_adapter.rb +37 -0
  92. data/lib/merb/request.rb +421 -0
  93. data/lib/merb/router.rb +576 -0
  94. data/lib/merb/{merb_server.rb → server.rb} +275 -71
  95. data/lib/merb/session.rb +10 -10
  96. data/lib/merb/session/cookie_store.rb +125 -0
  97. data/lib/merb/session/{merb_mem_cache_session.rb → mem_cache_session.rb} +22 -9
  98. data/lib/merb/session/{merb_memory_session.rb → memory_session.rb} +15 -11
  99. data/lib/merb/template.rb +35 -8
  100. data/lib/merb/template/erubis.rb +16 -10
  101. data/lib/merb/template/haml.rb +33 -20
  102. data/lib/merb/template/markaby.rb +16 -14
  103. data/lib/merb/template/xml_builder.rb +8 -4
  104. data/lib/merb/test/{merb_fake_request.rb → fake_request.rb} +11 -5
  105. data/lib/merb/test/helper.rb +31 -0
  106. data/lib/merb/test/hpricot.rb +136 -0
  107. data/lib/merb/test/{merb_multipart.rb → multipart.rb} +1 -1
  108. data/lib/merb/test/rspec.rb +93 -0
  109. data/lib/merb/{merb_upload_handler.rb → upload_handler.rb} +5 -6
  110. data/lib/merb/{merb_upload_progress.rb → upload_progress.rb} +1 -1
  111. data/lib/merb/{merb_view_context.rb → view_context.rb} +27 -42
  112. data/lib/{merb_tasks.rb → tasks.rb} +0 -0
  113. data/lib/tasks/merb.rake +21 -11
  114. data/merb_default_generators/model/USAGE +0 -0
  115. data/merb_default_generators/model/model_generator.rb +16 -0
  116. data/merb_default_generators/model/templates/new_model_template.erb +5 -0
  117. data/merb_default_generators/resource_controller/USAGE +0 -0
  118. data/merb_default_generators/resource_controller/resource_controller_generator.rb +26 -0
  119. data/merb_default_generators/resource_controller/templates/controller.rb +30 -0
  120. data/merb_default_generators/resource_controller/templates/edit.html.erb +1 -0
  121. data/merb_default_generators/resource_controller/templates/helper.rb +5 -0
  122. data/merb_default_generators/resource_controller/templates/index.html.erb +1 -0
  123. data/merb_default_generators/resource_controller/templates/new.html.erb +1 -0
  124. data/merb_default_generators/resource_controller/templates/show.html.erb +1 -0
  125. data/merb_generators/controller/USAGE +5 -0
  126. data/merb_generators/controller/controller_generator.rb +16 -0
  127. data/merb_generators/controller/templates/controller.rb +8 -0
  128. data/merb_generators/controller/templates/helper.rb +5 -0
  129. data/merb_generators/controller/templates/index.html.erb +3 -0
  130. data/merb_generators/resource/USAGE +0 -0
  131. data/merb_generators/resource/resource_generator.rb +60 -0
  132. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +67 -0
  133. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +8 -0
  134. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +12 -0
  135. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +5 -0
  136. data/rspec_generators/merb_controller_test/templates/index_spec.rb +12 -0
  137. data/rspec_generators/merb_controller_test/templates/new_spec.rb +12 -0
  138. data/rspec_generators/merb_controller_test/templates/show_spec.rb +5 -0
  139. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +26 -0
  140. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +7 -0
  141. data/script/destroy +14 -0
  142. data/script/generate +14 -0
  143. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +53 -0
  144. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +17 -0
  145. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +9 -0
  146. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +29 -0
  147. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +9 -0
  148. metadata +172 -94
  149. data/examples/README_EXAMPLES +0 -10
  150. data/examples/skeleton/Rakefile +0 -68
  151. data/examples/skeleton/dist/app/views/layout/application.herb +0 -12
  152. data/examples/skeleton/dist/conf/database.yml +0 -23
  153. data/examples/skeleton/dist/conf/merb.yml +0 -57
  154. data/examples/skeleton/dist/conf/merb_init.rb +0 -24
  155. data/examples/skeleton/dist/conf/router.rb +0 -22
  156. data/examples/skeleton/dist/conf/upload.conf +0 -5
  157. data/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb +0 -14
  158. data/examples/skeleton/script/new_migration +0 -21
  159. data/lib/merb/core_ext/merb_string.rb +0 -18
  160. data/lib/merb/merb_controller.rb +0 -206
  161. data/lib/merb/merb_dispatcher.rb +0 -87
  162. data/lib/merb/merb_exceptions.rb +0 -319
  163. data/lib/merb/merb_part_controller.rb +0 -42
  164. data/lib/merb/merb_plugins.rb +0 -293
  165. data/lib/merb/merb_request.rb +0 -165
  166. data/lib/merb/merb_router.rb +0 -309
  167. data/lib/merb/merb_yaml_store.rb +0 -31
  168. data/lib/merb/mixins/render_mixin.rb +0 -283
  169. data/lib/merb/mixins/responder_mixin.rb +0 -159
  170. data/lib/merb/session/merb_ar_session.rb +0 -131
  171. data/lib/merb/vendor/paginator/README.txt +0 -84
  172. data/lib/merb/vendor/paginator/paginator.rb +0 -124
  173. data/lib/tasks/db.rake +0 -55
@@ -1,131 +0,0 @@
1
- require 'active_record'
2
-
3
- module Merb
4
-
5
- module SessionMixin
6
-
7
- def setup_session
8
- MERB_LOGGER.info("Setting up session")
9
- before = @_cookies[_session_id_key]
10
- @_session, @_cookies[_session_id_key] = Merb::Session.persist(@_cookies[_session_id_key])
11
- @_fingerprint = Marshal.dump(@_session.data).hash
12
- @_new_cookie = @_cookies[_session_id_key] != before
13
- end
14
-
15
- def finalize_session
16
- MERB_LOGGER.info("Finalize session")
17
- @_session.save if @_fingerprint != Marshal.dump(@_session.data).hash
18
- set_cookie(_session_id_key, @_session.session_id, _session_expiry) if (@_new_cookie || @_session.needs_new_cookie)
19
- end
20
- end
21
-
22
- class Session < ::ActiveRecord::Base
23
- # Customizable data column name. Defaults to 'data'.
24
- cattr_accessor :data_column_name
25
- self.data_column_name = 'data'
26
- before_save :marshal_data!
27
- before_save :raise_on_session_data_overflow!
28
- attr_accessor :needs_new_cookie
29
-
30
- class << self
31
- # Generates a new session ID and creates a row for the new session in the database.
32
- def generate
33
- sid = Merb::SessionMixin::rand_uuid
34
- create(:session_id => sid, :data => {})
35
- end
36
-
37
- # Gets the existing session based on the <tt>session_id</tt> available in cookies.
38
- # If none is found, generates a new session.
39
- def persist(session_id)
40
- if session_id
41
- session = find_by_session_id(session_id)
42
- end
43
- unless session
44
- session = generate
45
- end
46
- [session, session.session_id]
47
- end
48
-
49
- # Don't try to reload ARStore::Session in dev mode.
50
- def reloadable? #:nodoc:
51
- false
52
- end
53
-
54
- def data_column_size_limit
55
- @data_column_size_limit ||= columns_hash[@@data_column_name].limit
56
- end
57
-
58
- def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
59
- def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
60
-
61
- def create_table!
62
- connection.execute <<-end_sql
63
- CREATE TABLE #{table_name} (
64
- id INTEGER PRIMARY KEY,
65
- #{connection.quote_column_name('session_id')} TEXT UNIQUE,
66
- #{connection.quote_column_name(@@data_column_name)} TEXT(255)
67
- )
68
- end_sql
69
- end
70
-
71
- def drop_table!
72
- connection.execute "DROP TABLE #{table_name}"
73
- end
74
- end
75
-
76
- # Regenerate the Session ID
77
- def regenerate
78
- new_id = Merb::SessionMixin::rand_uuid
79
- update_attributes({:session_id => new_id})
80
- self.needs_new_cookie=true
81
- end
82
-
83
- # Recreates the cookie with the default expiration time
84
- # Useful during log in for pushing back the expiration date
85
- def refresh_expiration
86
- self.needs_new_cookie=true
87
- end
88
-
89
- # Lazy-delete of session data
90
- def delete
91
- self.data = {}
92
- end
93
-
94
- def [](key)
95
- data[key]
96
- end
97
-
98
- def []=(key, val)
99
- data[key] = val
100
- end
101
-
102
- # Lazy-unmarshal session state.
103
- def data
104
- @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {}
105
- end
106
-
107
- # Has the session been loaded yet?
108
- def loaded?
109
- !! @data
110
- end
111
-
112
- private
113
- attr_writer :data
114
-
115
- def marshal_data!
116
- return false if !loaded?
117
- write_attribute(@@data_column_name, self.class.marshal(self.data))
118
- end
119
-
120
- # Ensures that the data about to be stored in the database is not
121
- # larger than the data storage column. Raises
122
- # ActionController::SessionOverflowError.
123
- def raise_on_session_data_overflow!
124
- return false if !loaded?
125
- limit = self.class.data_column_size_limit
126
- if loaded? and limit and read_attribute(@@data_column_name).size > limit
127
- raise MerbController::SessionOverflowError
128
- end
129
- end
130
- end
131
- end
@@ -1,84 +0,0 @@
1
- paginator
2
- by Bruce Williams
3
- http://codefluency.com
4
-
5
- == DESCRIPTION:
6
-
7
- Paginator is a simple pagination class that provides a generic interface suitable
8
- for use in any Ruby program.
9
-
10
- == FEATURES/PROBLEMS:
11
-
12
- Paginator doesn't make any assumptions as to how data is retrieved; you just
13
- have to provide it with the total number of objects and a way to pull a specific
14
- set of objects based on the offset and number of objects per page.
15
-
16
- == SYNOPSIS:
17
-
18
- In both of these examples I'm using a PER_PAGE constant (the number of items per page), but it's merely for labeling purposes.
19
-
20
- You could, of course, just pass in the number of items per page directly to the initializer without assigning it somewhere beforehand.
21
-
22
- === In a Rails Application
23
-
24
- def index
25
- @pager = ::Paginator.new(Foo.count, PER_PAGE) do |offset, per_page|
26
- Foo.find(:all, :limit => per_page, :offset => offset)
27
- end
28
- @page = @pager.page(params[:page])
29
- # respond_to here if you want it
30
- end
31
-
32
- # In your view
33
- <% @page.items.each do |foo| %>
34
- <%# Show something for each item %>
35
- <% end %>
36
- <%= @page.number %>
37
- <%= link_to("Prev", foos_url(:page => @page.prev.number)) if @page.prev? %>
38
- <%= link_to("Next", foos_url(:page => @page.next.number)) if @page.next? %>
39
-
40
- === Anything else
41
-
42
- bunch_o_data = (1..60).to_a
43
- pager = Paginator.new(bunch_o_data.size, PER_PAGE) do |offset, per_page|
44
- bunch_o_data[offset,per_page]
45
- end
46
- pager.each do |page|
47
- puts "Page ##{page.number}"
48
- page.each do |item|
49
- puts item
50
- end
51
- end
52
-
53
- == REQUIREMENTS:
54
-
55
- None.
56
-
57
- == INSTALL:
58
-
59
- No special instructions.
60
-
61
- == LICENSE:
62
-
63
- (The MIT License)
64
-
65
- Copyright (c) 2006 Bruce Williams (http://codefluency.com)
66
-
67
- Permission is hereby granted, free of charge, to any person obtaining
68
- a copy of this software and associated documentation files (the
69
- 'Software'), to deal in the Software without restriction, including
70
- without limitation the rights to use, copy, modify, merge, publish,
71
- distribute, sublicense, and/or sell copies of the Software, and to
72
- permit persons to whom the Software is furnished to do so, subject to
73
- the following conditions:
74
-
75
- The above copyright notice and this permission notice shall be
76
- included in all copies or substantial portions of the Software.
77
-
78
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
79
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
80
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
81
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
82
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
83
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
84
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,124 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Merb
4
- class Paginator
5
-
6
- VERSION = '1.0.6'
7
-
8
- class ArgumentError < ::ArgumentError; end
9
- class MissingCountError < ArgumentError; end
10
- class MissingSelectError < ArgumentError; end
11
-
12
- attr_reader :per_page
13
-
14
- # Instantiate a new Paginator object
15
- #
16
- # Provide:
17
- # * A total count of the number of objects to paginate
18
- # * The number of objects in each page
19
- # * A block that returns the array of items
20
- # * The block is passed the item offset
21
- # (and the number of items to show per page, for
22
- # convenience, if the arity is 2)
23
- def initialize(count, per_page, &select)
24
- @count, @per_page = count, per_page
25
- unless select
26
- raise MissingSelectError, "Must provide block to select data for each page"
27
- end
28
- @select = select
29
- end
30
-
31
- # Total number of pages
32
- def number_of_pages
33
- (@count / @per_page) + (@count % @per_page > 0 ? 1 : 0)
34
- end
35
-
36
- # First page object
37
- def first
38
- page 1
39
- end
40
-
41
- # Last page object
42
- def last
43
- page number_of_pages
44
- end
45
-
46
- # Iterate through pages
47
- def each
48
- each_with_index do |item, index|
49
- yield item
50
- end
51
- end
52
-
53
- # Iterate through pages with indices
54
- def each_with_index
55
- 1.upto(number_of_pages) do |number|
56
- yield(page(number), number - 1)
57
- end
58
- end
59
-
60
- # Retrieve page object by number
61
- def page(number)
62
- number = (n = number.to_i) > 0 ? n : 1
63
- Page.new(self, number, lambda {
64
- offset = (number - 1) * @per_page
65
- args = [offset]
66
- args << @per_page if @select.arity == 2
67
- @select.call(*args)
68
- })
69
- end
70
-
71
- # Page object
72
- #
73
- # Retrieves items for a page and provides metadata about the position
74
- # of the page in the paginator
75
- class Page
76
-
77
- extend Forwardable
78
- def_delegator :@pager, :first, :first
79
- def_delegator :@pager, :last, :last
80
- def_delegator :items, :each
81
- def_delegator :items, :each_with_index
82
-
83
- attr_reader :number, :pager
84
-
85
- def initialize(pager, number, select) #:nodoc:
86
- @pager, @number = pager, number
87
- @select = select
88
- end
89
-
90
- # Retrieve the items for this page
91
- # * Caches
92
- def items
93
- @items ||= @select.call
94
- end
95
-
96
- # Checks to see if there's a page before this one
97
- def prev?
98
- @number > 1
99
- end
100
-
101
- # Get previous page (if possible)
102
- def prev
103
- @pager.page(@number - 1) if prev?
104
- end
105
-
106
- # Checks to see if there's a page after this one
107
- def next?
108
- @number < @pager.number_of_pages
109
- end
110
-
111
- # Get next page (if possible)
112
- def next
113
- @pager.page(@number + 1) if next?
114
- end
115
-
116
- def ==(other) #:nodoc:
117
- @pager == other.pager && self.number == other.number
118
- end
119
-
120
- end
121
-
122
- end
123
-
124
- end
@@ -1,55 +0,0 @@
1
- MERB_ROOT = Dir.pwd
2
-
3
- desc "Setup the Merb Environment by requiring merb and loading your merb_init.rb"
4
- task :merb_env do
5
- require 'rubygems'
6
- require 'merb'
7
- Merb::Server.config[:environment] = ENV['MERB_ENV'] if ENV['MERB_ENV']
8
- MERB_ENV = Merb::Server.config[:environment].nil? ? 'development' : Merb::Server.config[:environment]
9
- load MERB_ROOT+'/dist/conf/merb_init.rb'
10
- end
11
-
12
- namespace :db do
13
- desc "Migrate the database through scripts in dist/schema/migrate. Target specific version with VERSION=x"
14
- task :migrate => :merb_env do
15
- ActiveRecord::Migrator.migrate("dist/schema/migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
16
- Rake::Task["db:schema:dump"].invoke
17
- end
18
-
19
- namespace :schema do
20
- desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
21
- task :dump => :merb_env do
22
- require 'active_record/schema_dumper'
23
- File.open(ENV['SCHEMA'] || "dist/schema/schema.rb", "w") do |file|
24
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
25
- end
26
- end
27
-
28
- desc "Load a schema.rb file into the database"
29
- task :load => :merb_env do
30
- file = ENV['SCHEMA'] || "dist/schema/schema.rb"
31
- load(file)
32
- end
33
- end
34
-
35
- namespace :sessions do
36
- desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore"
37
- task :create => :merb_env do
38
- raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
39
- require 'rails_generator'
40
- require 'rails_generator/scripts/generate'
41
- Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "AddSessions"])
42
- end
43
-
44
- desc "Clear the sessions table"
45
- task :clear => :merb_env do
46
- session_table = 'session'
47
- session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names
48
- ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}"
49
- end
50
- end
51
- end
52
-
53
- def session_table_name
54
- ActiveRecord::Base.pluralize_table_names ? :sessions : :session
55
- end