netzke-basepack 0.5.14 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/.gitignore +3 -2
  2. data/CHANGELOG.rdoc +15 -0
  3. data/README.rdoc +45 -50
  4. data/Rakefile +8 -8
  5. data/TODO.rdoc +1 -6
  6. data/app/components/netzke/basepack/accordion_panel.rb +37 -0
  7. data/app/components/netzke/basepack/basic_app.rb +267 -0
  8. data/{lib/netzke → app/components/netzke/basepack}/basic_app/statusbar_ext.js +0 -0
  9. data/app/components/netzke/basepack/border_layout_panel.rb +39 -0
  10. data/app/components/netzke/basepack/form_panel.rb +102 -0
  11. data/app/components/netzke/basepack/form_panel/fields.rb +206 -0
  12. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js +0 -0
  13. data/app/components/netzke/basepack/form_panel/javascripts/pre.js +76 -0
  14. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/xcheckbox.js +0 -0
  15. data/app/components/netzke/basepack/form_panel/services.rb +99 -0
  16. data/app/components/netzke/basepack/grid_panel.rb +374 -0
  17. data/app/components/netzke/basepack/grid_panel/columns.rb +233 -0
  18. data/app/components/netzke/basepack/grid_panel/javascript.rb +69 -0
  19. data/app/components/netzke/basepack/grid_panel/javascripts/advanced_search.js +96 -0
  20. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/edit_in_form.js +5 -4
  21. data/{lib/netzke/grid_panel/javascripts/grid_panel_pre.js → app/components/netzke/basepack/grid_panel/javascripts/pre.js} +17 -37
  22. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/rows-dd.js +0 -0
  23. data/app/components/netzke/basepack/grid_panel/multi_edit_form.rb +16 -0
  24. data/app/components/netzke/basepack/grid_panel/record_form_window.rb +36 -0
  25. data/app/components/netzke/basepack/grid_panel/search_window.rb +56 -0
  26. data/app/components/netzke/basepack/grid_panel/services.rb +356 -0
  27. data/app/components/netzke/basepack/panel.rb +11 -0
  28. data/app/components/netzke/basepack/search_panel.rb +59 -0
  29. data/app/components/netzke/basepack/tab_panel.rb +32 -0
  30. data/app/components/netzke/basepack/window.rb +73 -0
  31. data/app/components/netzke/basepack/wrapper.rb +28 -0
  32. data/{lib/app → app}/models/netzke_field_list.rb +1 -1
  33. data/{lib/app → app}/models/netzke_model_attr_list.rb +0 -0
  34. data/{lib/app → app}/models/netzke_persistent_array_auto_model.rb +0 -0
  35. data/config/database.yml +35 -0
  36. data/features/accordion_panel.feature +15 -0
  37. data/features/basic_app.feature +12 -0
  38. data/features/form_panel.feature +40 -0
  39. data/features/grid_panel.feature +62 -0
  40. data/features/search_in_grid.feature +35 -0
  41. data/features/simple_panel.feature +15 -0
  42. data/features/step_definitions/accordion_steps.rb +9 -0
  43. data/features/step_definitions/generic_steps.rb +15 -0
  44. data/features/step_definitions/grid_panel_steps.rb +26 -0
  45. data/features/step_definitions/pickle_steps.rb +100 -0
  46. data/features/step_definitions/web_steps.rb +219 -0
  47. data/features/support/env.rb +66 -0
  48. data/features/support/paths.rb +59 -0
  49. data/features/support/pickle.rb +25 -0
  50. data/features/tab_panel.feature +15 -0
  51. data/features/window.feature +11 -0
  52. data/from_05_to_06.rdoc +2 -0
  53. data/javascripts/basepack.js +54 -2
  54. data/lib/netzke-basepack.rb +38 -25
  55. data/lib/netzke/active_record.rb +12 -4
  56. data/lib/netzke/active_record/attributes.rb +60 -5
  57. data/lib/netzke/active_record/combobox_options.rb +3 -2
  58. data/lib/netzke/active_record/relation_extensions.rb +35 -0
  59. data/lib/netzke/basepack.rb +27 -0
  60. data/lib/netzke/basepack/version.rb +11 -0
  61. data/lib/netzke/basepack/wrap_lazy_loaded.rb +26 -0
  62. data/lib/netzke/data_accessor.rb +60 -32
  63. data/lib/netzke/fields_configurator.rb +5 -9
  64. data/lib/netzke/masquerade_selector.rb +1 -1
  65. data/locale/en.yml +16 -0
  66. data/netzke-basepack.gemspec +298 -0
  67. data/spec/active_record/attributes_spec.rb +14 -0
  68. data/spec/active_record/relation_extensions_spec.rb +44 -0
  69. data/spec/components/form_panel_spec.rb +70 -0
  70. data/spec/components/grid_panel_spec.rb +10 -0
  71. data/spec/factories.rb +9 -0
  72. data/spec/spec_helper.rb +35 -0
  73. data/test/rails_app/.gitignore +4 -0
  74. data/test/rails_app/Gemfile +32 -0
  75. data/test/rails_app/Gemfile.lock +171 -0
  76. data/test/rails_app/README +256 -0
  77. data/test/rails_app/Rakefile +7 -0
  78. data/test/rails_app/app/components/generic_user_form.rb +12 -0
  79. data/test/rails_app/app/components/simple_accordion.rb +11 -0
  80. data/test/rails_app/app/components/simple_basic_app.rb +32 -0
  81. data/test/rails_app/app/components/simple_panel.rb +17 -0
  82. data/test/rails_app/app/components/simple_tab_panel.rb +11 -0
  83. data/test/rails_app/app/components/simple_wrapper.rb +7 -0
  84. data/test/rails_app/app/components/some_border_layout.rb +24 -0
  85. data/test/rails_app/app/components/some_search_panel.rb +34 -0
  86. data/test/rails_app/app/components/some_tab_panel.rb +15 -0
  87. data/test/rails_app/app/components/user_form.rb +21 -0
  88. data/test/rails_app/app/components/user_form_with_default_fields.rb +8 -0
  89. data/test/rails_app/app/components/user_grid.rb +4 -0
  90. data/test/rails_app/app/components/window_component_loader.rb +17 -0
  91. data/test/{app_root/app/controllers/application.rb → rails_app/app/controllers/application_controller.rb} +1 -0
  92. data/test/rails_app/app/controllers/components_controller.rb +6 -0
  93. data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
  94. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  95. data/test/{app_root → rails_app}/app/models/role.rb +0 -0
  96. data/test/rails_app/app/models/user.rb +6 -0
  97. data/test/rails_app/app/presenters/forms/generic_user.rb +6 -0
  98. data/test/rails_app/app/views/layouts/application.html.erb +13 -0
  99. data/test/rails_app/config.ru +4 -0
  100. data/test/rails_app/config/application.rb +45 -0
  101. data/test/rails_app/config/boot.rb +13 -0
  102. data/test/rails_app/config/database.yml +35 -0
  103. data/test/rails_app/config/environment.rb +6 -0
  104. data/test/rails_app/config/environments/development.rb +22 -0
  105. data/test/rails_app/config/environments/production.rb +49 -0
  106. data/test/rails_app/config/environments/test.rb +35 -0
  107. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  108. data/test/rails_app/config/initializers/inflections.rb +10 -0
  109. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  110. data/test/rails_app/config/initializers/netzke.rb +7 -0
  111. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  112. data/test/rails_app/config/initializers/session_store.rb +8 -0
  113. data/test/rails_app/config/locales/es.yml +12 -0
  114. data/test/rails_app/config/routes.rb +65 -0
  115. data/test/rails_app/db/development_structure.sql +39 -0
  116. data/test/{app_root/db/migrate/20081222035855_create_netzke_preferences.rb → rails_app/db/migrate/20100905214933_create_netzke_preferences.rb} +2 -4
  117. data/test/{app_root/db/migrate/20090423222114_create_users.rb → rails_app/db/migrate/20100914104207_create_users.rb} +4 -1
  118. data/test/{app_root/db/migrate/20090423214303_create_roles.rb → rails_app/db/migrate/20100914104236_create_roles.rb} +2 -0
  119. data/test/rails_app/db/schema.rb +38 -0
  120. data/test/rails_app/db/seeds.rb +20 -0
  121. data/test/rails_app/features/support/paths.rb +47 -0
  122. data/test/{app_root/config/environments/in_memory.rb → rails_app/lib/tasks/.gitkeep} +0 -0
  123. data/test/rails_app/public/404.html +26 -0
  124. data/test/rails_app/public/422.html +26 -0
  125. data/test/rails_app/public/500.html +26 -0
  126. data/test/{app_root/config/environments/mysql.rb → rails_app/public/favicon.ico} +0 -0
  127. data/test/rails_app/public/images/header-deco.gif +0 -0
  128. data/test/rails_app/public/images/rails.png +0 -0
  129. data/test/rails_app/public/javascripts/application.js +2 -0
  130. data/test/rails_app/public/javascripts/controls.js +965 -0
  131. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  132. data/test/rails_app/public/javascripts/effects.js +1123 -0
  133. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  134. data/test/rails_app/public/javascripts/rails.js +175 -0
  135. data/test/rails_app/public/robots.txt +5 -0
  136. data/test/{app_root/config/environments/postgresql.rb → rails_app/public/stylesheets/.gitkeep} +0 -0
  137. data/test/rails_app/script/rails +6 -0
  138. data/test/rails_app/spec/models/role_spec.rb +5 -0
  139. data/test/rails_app/spec/models/user_spec.rb +5 -0
  140. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  141. data/test/rails_app/test/test_helper.rb +13 -0
  142. data/test/{app_root/config/environments/sqlite.rb → rails_app/vendor/plugins/.gitkeep} +0 -0
  143. data/test/unit/accordion_panel_test.rb +3 -3
  144. data/test/unit/active_record_basepack_test.rb +4 -4
  145. data/test/unit/tab_panel_test.rb +4 -4
  146. metadata +199 -119
  147. data/lib/netzke/accordion_panel.rb +0 -115
  148. data/lib/netzke/active_record/data_accessor.rb +0 -25
  149. data/lib/netzke/attributes_configurator.rb +0 -195
  150. data/lib/netzke/basic_app.rb +0 -368
  151. data/lib/netzke/border_layout_panel.rb +0 -130
  152. data/lib/netzke/configuration_panel.rb +0 -24
  153. data/lib/netzke/form_panel.rb +0 -138
  154. data/lib/netzke/form_panel/form_panel_api.rb +0 -81
  155. data/lib/netzke/form_panel/form_panel_fields.rb +0 -149
  156. data/lib/netzke/form_panel/form_panel_js.rb +0 -163
  157. data/lib/netzke/grid_panel.rb +0 -367
  158. data/lib/netzke/grid_panel/grid_panel_api.rb +0 -364
  159. data/lib/netzke/grid_panel/grid_panel_columns.rb +0 -232
  160. data/lib/netzke/grid_panel/grid_panel_js.rb +0 -73
  161. data/lib/netzke/grid_panel/javascripts/advanced_search.js +0 -65
  162. data/lib/netzke/grid_panel/multi_edit_form.rb +0 -14
  163. data/lib/netzke/grid_panel/record_form_window.rb +0 -50
  164. data/lib/netzke/panel.rb +0 -11
  165. data/lib/netzke/plugins/configuration_tool.rb +0 -121
  166. data/lib/netzke/property_editor.rb +0 -111
  167. data/lib/netzke/property_editor/helper_model.rb +0 -122
  168. data/lib/netzke/search_panel.rb +0 -199
  169. data/lib/netzke/tab_panel.rb +0 -174
  170. data/lib/netzke/table_editor.rb +0 -118
  171. data/lib/netzke/tree_panel.rb +0 -25
  172. data/lib/netzke/window.rb +0 -82
  173. data/lib/netzke/wrapper.rb +0 -42
  174. data/test/app_root/app/models/book.rb +0 -9
  175. data/test/app_root/app/models/category.rb +0 -2
  176. data/test/app_root/app/models/city.rb +0 -3
  177. data/test/app_root/app/models/continent.rb +0 -2
  178. data/test/app_root/app/models/country.rb +0 -3
  179. data/test/app_root/app/models/genre.rb +0 -3
  180. data/test/app_root/app/models/user.rb +0 -3
  181. data/test/app_root/config/boot.rb +0 -114
  182. data/test/app_root/config/database.yml +0 -21
  183. data/test/app_root/config/environment.rb +0 -14
  184. data/test/app_root/config/environments/sqlite3.rb +0 -0
  185. data/test/app_root/config/routes.rb +0 -4
  186. data/test/app_root/db/migrate/20081222033343_create_books.rb +0 -15
  187. data/test/app_root/db/migrate/20081222033440_create_genres.rb +0 -15
  188. data/test/app_root/db/migrate/20081223024935_create_categories.rb +0 -13
  189. data/test/app_root/db/migrate/20081223025635_create_countries.rb +0 -14
  190. data/test/app_root/db/migrate/20081223025653_create_continents.rb +0 -13
  191. data/test/app_root/db/migrate/20081223025732_create_cities.rb +0 -15
  192. data/test/app_root/db/migrate/20090102223630_create_netzke_field_lists.rb +0 -18
  193. data/test/app_root/script/console +0 -7
  194. data/test/app_root/vendor/plugins/acts_as_list/README +0 -23
  195. data/test/app_root/vendor/plugins/acts_as_list/init.rb +0 -3
  196. data/test/app_root/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
@@ -1,118 +0,0 @@
1
- module Netzke
2
- # == TableEditor CURRENTLY NOT SUPPORTED AND MAY BE BROKEN. Instead, use GridPanel's adding/editing records in form.
3
- #
4
- # A widget used for editing a DB table. It contains a grid and a form which may display different DB fields,
5
- # configured by grid_columns and form_fields configuration options respectively
6
- class TableEditor < BorderLayoutPanel
7
-
8
- def self.js_extend_properties
9
- {
10
- :init_component => <<-END_OF_JAVASCRIPT.l,
11
- function(){
12
- #{js_full_class_name}.superclass.initComponent.call(this);
13
-
14
- var setCentralWidgetEvents = function(){
15
- this.getCenterWidget().on('addclick', function(){
16
- this.getFormWidget().getForm().reset();
17
-
18
- var firstEditableField = null;
19
- this.getFormWidget().getForm().items.each(function(f){
20
- if (!f.hidden && !f.disabled){
21
- firstEditableField = f;
22
- return false; // break the loop
23
- }
24
- })
25
- if (firstEditableField) firstEditableField.focus();
26
-
27
- this.getFormWidget().ownerCt.expand();
28
-
29
- this.getCenterWidget().getSelectionModel().clearSelections();
30
- this.lastSelectedRow = null;
31
- return false;
32
- }, this)
33
-
34
- this.getCenterWidget().on('rowclick', this.onRowClick, this);
35
- };
36
-
37
- this.getCenterWidget().ownerCt.on('add', setCentralWidgetEvents, this);
38
- setCentralWidgetEvents.call(this);
39
-
40
- }
41
- END_OF_JAVASCRIPT
42
-
43
-
44
- :get_form_widget => <<-END_OF_JAVASCRIPT.l,
45
- function(){
46
- return this.getRegionWidget(this.region);
47
- }
48
- END_OF_JAVASCRIPT
49
-
50
- # a grid row clicked
51
- :on_row_click => <<-END_OF_JAVASCRIPT.l,
52
- function(grid, index, e){
53
- // don't react if the selection hasn't changed
54
- if (index == this.lastSelectedRow) return false;
55
- this.lastSelectedRow = index;
56
-
57
- // get id of the record
58
- var recordId = this.getCenterWidget().getStore().getAt(index).get('id');
59
-
60
- // load the form with the record id
61
- this.getRegionWidget(this.region).loadRecord(recordId);
62
- }
63
- END_OF_JAVASCRIPT
64
-
65
- # after the form is submitted, reload the grid
66
- :on_form_actioncomplete => <<-END_OF_JAVASCRIPT.l
67
- function(grid, index, e){
68
- this.getRegionWidget('center').store.load()
69
- }
70
- END_OF_JAVASCRIPT
71
- }
72
- end
73
-
74
- def default_config
75
- # don't show the title on the top level
76
- super.merge!({:ext_config => {:title => false}})
77
- end
78
-
79
- def js_config
80
- # the client side of the widget wants to know which region it uses
81
- super.merge({
82
- :region => config[:split_region]
83
- })
84
- end
85
-
86
- def initial_aggregatees
87
- split_region = config[:split_region] || :east
88
- split_size = config[:split_size] || 200
89
- {
90
- :center => {
91
- :class_name => "GridPanel",
92
- :model => config[:model],
93
- :ext_config => {
94
- :title => config[:grid_title] || config[:model].pluralize
95
- }
96
- }.deep_merge(config[:grid_config] || {}),
97
-
98
- split_region => {
99
- :class_name => "FormPanel",
100
- :model => config[:model],
101
- :region_config => {
102
- :width => split_size,
103
- :height => split_size,
104
- :split => true,
105
- :collapsible => true
106
- },
107
- :ext_config => {
108
- :title => config[:form_title] || "#{config[:model]} details",
109
- :listeners => {:actioncomplete => {
110
- :fn => "function(f, a){this.ownerCt.ownerCt.onFormActioncomplete(f,a)}".l
111
- }}
112
- }
113
- }.deep_merge(config[:form_config] || {})
114
- }
115
- end
116
-
117
- end
118
- end
@@ -1,25 +0,0 @@
1
- class Netzke::TreePanel < Netzke::Base
2
- api :get_children
3
-
4
- def self.js_base_class
5
- "Ext.tree.TreePanel"
6
- end
7
-
8
- def self.js_extend_properties
9
- {
10
- :root => {:text => '/', :id => 'source'}
11
- }
12
- end
13
-
14
- def js_config
15
- super.deep_merge({
16
- :loader => {:data_url => global_id+"__get_children".l}
17
- })
18
- end
19
-
20
- def get_children(params)
21
- klass = config[:model].constantize
22
- node = params[:node] == 'source' ? klass.find_by_parent_id(nil) : klass.find(params[:node].to_i)
23
- node.children.map{|n| {:text => n.name, :id => n.id, :leaf => n.children.empty?}}
24
- end
25
- end
data/lib/netzke/window.rb DELETED
@@ -1,82 +0,0 @@
1
- module Netzke
2
- # == Window
3
- # Ext.Window-based widget able to nest other Netzke widgets
4
- #
5
- # == Features
6
- # * Persistent position and dimensions
7
- #
8
- # == Instance configuration
9
- # <tt>:item</tt> - nested Netzke widget, e.g.:
10
- #
11
- # netzke :window, :item => {:class_name => "GridPanel", :model => "User"}
12
- class Window < Base
13
- # Based on Ext.Window, naturally
14
- def self.js_base_class
15
- "Ext.Window"
16
- end
17
-
18
- # Set the passed item as the only aggregatee
19
- def initial_aggregatees
20
- res = {}
21
- res.merge!(:item => config[:item]) if config[:item]
22
- res
23
- end
24
-
25
- # Extends the JavaScript class
26
- def self.js_extend_properties
27
- {
28
- # we nest widget inside the "fit" layout
29
- :layout => "fit",
30
-
31
- # default width and height
32
- :width => 300,
33
- :height => 200,
34
-
35
- :init_component => <<-END_OF_JAVASCRIPT.l,
36
- function(){
37
- // superclass' initComponent
38
- #{js_full_class_name}.superclass.initComponent.call(this);
39
-
40
- // set the move and resize events after window is shown, so that they don't fire at initial rendering
41
- this.on("show", function(){
42
- this.on("move", this.onMoveResize, this);
43
- this.on("resize", this.onMoveResize, this);
44
- }, this);
45
-
46
- // instantiate the aggregatee
47
- if (this.itemConfig){
48
- this.instantiateChild(this.itemConfig);
49
- }
50
- }
51
- END_OF_JAVASCRIPT
52
-
53
- :on_move_resize => <<-END_OF_JAVASCRIPT.l,
54
- function(){
55
- var x = this.getPosition()[0], y = this.getPosition()[1], w = this.getSize().width, h = this.getSize().height;
56
-
57
- // Don't bother the server twice when both move and resize events are fired at the same time
58
- // (which happens when the left or upper window border is dragged)
59
- if (this.moveResizeTimer) {clearTimeout(this.moveResizeTimer)};
60
-
61
- this.moveResizeTimer = (function(sizeAndPosition){
62
- this.setSizeAndPosition(sizeAndPosition); // API call
63
- }).defer(10, this, [{x:x, y:y, w:w, h:h}]); // 10ms should be enough
64
- }
65
- END_OF_JAVASCRIPT
66
-
67
- }
68
- end
69
-
70
- # Processing API calls from client
71
- api :set_size_and_position
72
- def set_size_and_position(params)
73
- update_persistent_ext_config(
74
- :x => params[:x].to_i,
75
- :y => params[:y].to_i,
76
- :width => params[:w].to_i,
77
- :height => params[:h].to_i
78
- )
79
- {}
80
- end
81
- end
82
- end
@@ -1,42 +0,0 @@
1
- module Netzke
2
- # = Wrapper
3
- #
4
- # Simple Ext.Panel with layout 'fit' that wraps up another Netzke widget. Can be useful in HTML pages where
5
- # a widget should be dynamically configured, to not reload the entire page after configuration (Wrapper
6
- # will reload the widget automatically).
7
- #
8
- # == Configuration
9
- # * <tt>:item</tt> - configuration hash for wrapped widget
10
- #
11
- # Example:
12
- #
13
- # netzke :wrapper, :item => {
14
- # :class_name => "FormPanel",
15
- # :model => "User"
16
- # }
17
- class Wrapper < Base
18
- def self.js_extend_properties
19
- super.merge({
20
- :layout => 'fit',
21
-
22
- # invisible
23
- :header => false,
24
- :border => false,
25
-
26
- :init_component => <<-END_OF_JAVASCRIPT.l,
27
- function(){
28
- #{js_full_class_name}.superclass.initComponent.call(this);
29
-
30
- // instantiate the item
31
- this.instantiateChild(this.itemConfig);
32
- }
33
- END_OF_JAVASCRIPT
34
- })
35
- end
36
-
37
- def initial_aggregatees
38
- {:item => config[:item]}
39
- end
40
-
41
- end
42
- end
@@ -1,9 +0,0 @@
1
- class Book < ActiveRecord::Base
2
- belongs_to :genre
3
-
4
- netzke_attribute :recent
5
-
6
- def recent
7
- updated_at > 1.hour.ago ? "Yes" : "No"
8
- end
9
- end
@@ -1,2 +0,0 @@
1
- class Category < ActiveRecord::Base
2
- end
@@ -1,3 +0,0 @@
1
- class City < ActiveRecord::Base
2
- belongs_to :country
3
- end
@@ -1,2 +0,0 @@
1
- class Continent < ActiveRecord::Base
2
- end
@@ -1,3 +0,0 @@
1
- class Country < ActiveRecord::Base
2
- belongs_to :continent
3
- end
@@ -1,3 +0,0 @@
1
- class Genre < ActiveRecord::Base
2
- belongs_to :category
3
- end
@@ -1,3 +0,0 @@
1
- class User < ActiveRecord::Base
2
- belongs_to :role
3
- end
@@ -1,114 +0,0 @@
1
- # Allow customization of the rails framework path
2
- RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
3
-
4
- # Don't change this file!
5
- # Configure your app in config/environment.rb and config/environments/*.rb
6
-
7
- RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
8
-
9
- module Rails
10
- class << self
11
- def boot!
12
- unless booted?
13
- preinitialize
14
- pick_boot.run
15
- end
16
- end
17
-
18
- def booted?
19
- defined? Rails::Initializer
20
- end
21
-
22
- def pick_boot
23
- (vendor_rails? ? VendorBoot : GemBoot).new
24
- end
25
-
26
- def vendor_rails?
27
- File.exist?(RAILS_FRAMEWORK_ROOT)
28
- end
29
-
30
- def preinitialize
31
- load(preinitializer_path) if File.exist?(preinitializer_path)
32
- end
33
-
34
- def preinitializer_path
35
- "#{RAILS_ROOT}/config/preinitializer.rb"
36
- end
37
- end
38
-
39
- class Boot
40
- def run
41
- load_initializer
42
- Rails::Initializer.run(:set_load_path)
43
- end
44
- end
45
-
46
- class VendorBoot < Boot
47
- def load_initializer
48
- require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
49
- Rails::Initializer.run(:install_gem_spec_stubs)
50
- end
51
- end
52
-
53
- class GemBoot < Boot
54
- def load_initializer
55
- self.class.load_rubygems
56
- load_rails_gem
57
- require 'initializer'
58
- end
59
-
60
- def load_rails_gem
61
- if version = self.class.gem_version
62
- gem 'rails', version
63
- else
64
- gem 'rails'
65
- end
66
- rescue Gem::LoadError => load_error
67
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
68
- exit 1
69
- end
70
-
71
- class << self
72
- def rubygems_version
73
- Gem::RubyGemsVersion rescue nil
74
- end
75
-
76
- def gem_version
77
- if defined? RAILS_GEM_VERSION
78
- RAILS_GEM_VERSION
79
- elsif ENV.include?('RAILS_GEM_VERSION')
80
- ENV['RAILS_GEM_VERSION']
81
- else
82
- parse_gem_version(read_environment_rb)
83
- end
84
- end
85
-
86
- def load_rubygems
87
- require 'rubygems'
88
- min_version = '1.1.1'
89
- unless rubygems_version >= min_version
90
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
91
- exit 1
92
- end
93
-
94
- rescue LoadError
95
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
96
- exit 1
97
- end
98
-
99
- def parse_gem_version(text)
100
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
101
- end
102
-
103
- private
104
- def read_environment_rb
105
- environment_rb = "#{RAILS_ROOT}/config/environment.rb"
106
- environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
107
- File.read(environment_rb)
108
- end
109
- end
110
- end
111
- end
112
-
113
- # All that for this:
114
- Rails.boot!
@@ -1,21 +0,0 @@
1
- in_memory:
2
- adapter: sqlite3
3
- database: ":memory:"
4
- verbosity: quiet
5
- sqlite:
6
- adapter: sqlite
7
- dbfile: plugin_test.sqlite.db
8
- sqlite3:
9
- adapter: sqlite3
10
- dbfile: plugin_test.sqlite3.db
11
- postgresql:
12
- adapter: postgresql
13
- username: postgres
14
- password: postgres
15
- database: plugin_test
16
- mysql:
17
- adapter: mysql
18
- host: localhost
19
- username: root
20
- password:
21
- database: netzke_basepack_test