fortitude 0.0.10-java → 0.9.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a542c4ed9adc0639a95c15852b627673bb55c5
4
- data.tar.gz: 905df6f3d00b4e5740e9de43fd0486b4e4b9131e
3
+ metadata.gz: fe5a63f683c45d929d11bb4875c1e99042ee8e2a
4
+ data.tar.gz: 60eb4dbf18313d1e641b002df42f975d5fa14725
5
5
  SHA512:
6
- metadata.gz: 1245a668c62617e44b205e63f662b2a47735e97d13dd2315b26fdb832adec5a04f1eb5e464e0329f261cfcbdfe351d239306a95d97463714d4c5660c6c3cdd72
7
- data.tar.gz: 2f428702bbd1ed28557fe677a2f8b09c13a5864acec8669919fecd042b8a89bad35191dd706f24e3ed1bad4db7d55a47c211bd5fac05bba614eea917c57b2728
6
+ metadata.gz: 474bcd4bb594f99f5192d97c3c43738636da8ddcb762ae306942d6407eaf924ac6d82d369f4447d381b9871ec9646f0501aaf311871f1aaaced3d5ace37dab33
7
+ data.tar.gz: 94a87ae21f53e0164b12453fe6f59ce000904f1893fb149eec73b717b2a7149d8df2aa584ee27026bb064cc3a3ba901fd51fc6341c0ae0a0313e3ba76d4151e1
data/CHANGES.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Fortitude Releases
2
2
 
3
+ ## 0.9.0, 29 November 2014
4
+
5
+ Updated Fortitude's version number to 0.9.0: at this point, Fortitude should be considered fully production-ready,
6
+ as it is used successfully in multiple very large systems and bug reports are increasingly rare. I don't want to
7
+ release a 1.0 until there's excellent documentation, but the codebase seems to be ready.
8
+
9
+ * Added explicit support for eager-loading Fortitude widget classes under `views/` for Rails applications. This both
10
+ should improve first-run performance of Fortitude-using Rails applications in production, and should avoid an
11
+ occasional problem where Fortitude widget classes were not properly loaded in environments that used eager loading,
12
+ rather than autoloading, for classes.
13
+
3
14
  ## 0.0.10, 25 November 2014
4
15
 
5
16
  * Fixed an issue where `#capture` was not working properly if you rendered a widget using `render :widget =>` in a
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem 'erector'
7
7
  # gem 'erector-rails4', :path => '../erector-rails4'
8
+ gem 'oop_rails_server', :path => '../oop_rails_server'
@@ -17,7 +17,8 @@ else
17
17
  rescue LoadError => le
18
18
  $stderr.puts <<-EOM
19
19
  WARNING: The Fortitude gem cannot load its native extensions. Performance may be reduced by a factor of 3-5x!
20
- Load path: #{$:.inspect}
20
+ Load path:
21
+ #{$:.join("\n ")}
21
22
  Error: #{le.message} (#{le.class})
22
23
  EOM
23
24
  native_loaded = false
@@ -71,6 +71,10 @@ module Fortitude
71
71
  ::ActiveSupport::Dependencies.module_eval do
72
72
  @@_fortitude_views_root = views_root
73
73
 
74
+ def self._fortitude_views_root
75
+ @@_fortitude_views_root
76
+ end
77
+
74
78
  # This is the method that gets called to auto-generate namespacing empty
75
79
  # modules (_e.g._, the toplevel <tt>Views::</tt> module) for directories
76
80
  # under an autoload path.
@@ -176,8 +180,54 @@ module Fortitude
176
180
  alias_method_chain :search_for_file, :fortitude
177
181
  end
178
182
 
183
+ # Two important comments here:
184
+ #
185
+ # 1: We also need to patch ::Rails::Engine.eager_load! so that it loads classes under app/views/. However, we
186
+ # can't just add it to the normal eager load paths, because that will allow people to do "require 'foo/bar'"
187
+ # and have it match app/views/foo/bar.rb, which we don't want. So, instead, we load these classes ourselves.
188
+ # Note that we ALSO have to do things slightly differently than Rails does it, because we need to skip loading
189
+ # 'foo.rb' if 'foo.html.rb' exists -- and because we have to require the fully-qualified pathname, since
190
+ # app/views is not actually on the load path.
191
+ #
192
+ # 2: I (ageweke) added this very late in the path of Fortitude development, after trying to use Fortitude in a
193
+ # deployment (production) environment in which widgets just weren't getting loaded at all. Yet there's something
194
+ # I don't understand: clearly, without this code, widgets will not be eager-loaded (which is probably not a
195
+ # great thing for performance reasons)...but I think they still should get auto-loaded and hence actually work
196
+ # just fine. But they don't in that environment (you'll get errors like "uninitialized constant Views::Base").
197
+ # Since I understand what's going on and have the fix for it here, that's fine...except that I can't seem to
198
+ # write a spec for it, because I don't know how to actually *make* it fail. If anybody comes along later and
199
+ # knows what would make it fail (and I double-checked, and we don't have autoloading disabled in production or
200
+ # anything like that), let me know, so that I can write a spec for this. Thanks!
201
+ ::Rails::Engine.class_eval do
202
+ def eager_load_with_fortitude!
203
+ eager_load_without_fortitude!
204
+ eager_load_fortitude_views!
205
+ end
206
+
207
+ def eager_load_fortitude_views!
208
+ load_path = ::ActiveSupport::Dependencies._fortitude_views_root
209
+ all_files = Dir.glob("#{load_path}/**/*.rb")
210
+ matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
211
+
212
+ all_files.sort.each do |full_path|
213
+ filename = File.basename(full_path, ".rb")
214
+ directory = File.dirname(full_path)
215
+
216
+ longer_name_regex = /^#{Regexp.escape(filename)}\..+\.rb$/i
217
+ longer_name = Dir.entries(directory).detect { |e| e =~ longer_name_regex }
218
+
219
+ unless longer_name
220
+ require_dependency File.join('views', full_path.sub(matcher, '\1'))
221
+ end
222
+ end
223
+ end
224
+
225
+ alias_method_chain :eager_load!, :fortitude
226
+ end
227
+
179
228
  # And, finally, this is where we add our root to the set of autoload paths.
180
229
  ::ActiveSupport::Dependencies.autoload_paths << views_root
230
+ # app.config.eager_load_paths << views_root
181
231
 
182
232
  # This is our support for partials. Fortitude doesn't really have a distinction between
183
233
  # partials and "full" templates -- everything is just a widget, which is much more elegant --
@@ -1,3 +1,3 @@
1
1
  module Fortitude
2
- VERSION = "0.0.10"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -1,11 +1,6 @@
1
1
  describe "Rails class-loading support", :type => :rails do
2
2
  uses_rails_with_template :class_loading_system_spec
3
3
 
4
- it "should not load classes under app/views without the Views:: prefix" do
5
- expect_exception('the_class_should_not_load', 'NameError',
6
- /uninitialized constant ClassLoadingSystemSpec::ClassShouldNotLoad/i)
7
- end
8
-
9
4
  it "should allow me to define classes under Views:: outside of app/views, like in lib/views" do
10
5
  expect_match('lib_views', /hello: i am lib\/views/)
11
6
  end
@@ -53,9 +48,9 @@ describe "Rails class-loading support", :type => :rails do
53
48
  expect_match('bar', /bar WITH html/)
54
49
  end
55
50
 
56
- # it "should not let me define a widget in a file starting with an underscore, and autoload it" do
57
- # expect_exception('underscore_widget', 'NameError', /uninitialized constant Views::ClassLoadingSystemSpec::UnderscoreWidget/)
58
- # end
51
+ it "should let me define a widget in a file starting with an underscore, and autoload it" do
52
+ expect_match('underscore_widget_surrounding', /surrounding_widget before.*this is underscore_widget.*surrounding_widget after/)
53
+ end
59
54
 
60
55
  it "should not let me 'require' files in app/views without a views/ prefix" do
61
56
  expect_exception('require_loaded_underscore_widget_without_views', 'LoadError', /(cannot load such file|no such file to load)/)
@@ -68,4 +63,8 @@ describe "Rails class-loading support", :type => :rails do
68
63
  it "should let me render a widget defined outside of app/views/ if I use render :widget" do
69
64
  expect_match('render_widget_outside_app_views', /arbitrary_name_some_widget/)
70
65
  end
66
+
67
+ it "should not load view classes with any module nesting applied" do
68
+ expect_match('show_module_nesting', /module_nesting: \[\]/)
69
+ end
71
70
  end
@@ -23,6 +23,11 @@ describe "Rails development-mode support", :type => :rails do
23
23
  expect_match("reload_widget_with_html_extension", /with_html_extension.*helper: yo/)
24
24
  end
25
25
 
26
+ it "should not autoload classes that live under views/ but don't start with a Views:: prefix" do
27
+ expect_exception('the_class_should_not_load', 'NameError',
28
+ /uninitialized constant DevelopmentModeSystemSpec::ClassShouldNotLoad/i)
29
+ end
30
+
26
31
  it "should let you change the controller, and that should work fine, too" do
27
32
  expect(rails_server.get("replaced/reload_widget")).to match(/datum\s+one\s+datum/)
28
33
  sleep 1
@@ -1,8 +1,4 @@
1
1
  class ClassLoadingSystemSpecController < ApplicationController
2
- def the_class_should_not_load
3
- render :text => ::ClassLoadingSystemSpec::ClassShouldNotLoad.name
4
- end
5
-
6
2
  def lib_views
7
3
  # nothing here
8
4
  end
@@ -53,6 +49,10 @@ class ClassLoadingSystemSpecController < ApplicationController
53
49
  # nothing here
54
50
  end
55
51
 
52
+ def underscore_widget_surrounding
53
+ # nothing here
54
+ end
55
+
56
56
  def foo
57
57
  # nothing here
58
58
  end
@@ -75,4 +75,8 @@ class ClassLoadingSystemSpecController < ApplicationController
75
75
  require 'arbitrary_name/some_widget'
76
76
  render :widget => ArbitraryName::SomeWidget.new
77
77
  end
78
+
79
+ def show_module_nesting
80
+ # nothing here
81
+ end
78
82
  end
@@ -0,0 +1,7 @@
1
+ $_show_module_nesting = Module.nesting
2
+
3
+ class Views::ClassLoadingSystemSpec::ShowModuleNesting < Fortitude::Widgets::Html5
4
+ def content
5
+ text "module_nesting: #{$_show_module_nesting.inspect}"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Views::ClassLoadingSystemSpec::UnderscoreWidget < Fortitude::Widgets::Html5
2
+ def content
3
+ text "this is underscore_widget"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Views::ClassLoadingSystemSpec::UnderscoreWidgetSurrounding < Fortitude::Widgets::Html5
2
+ def content
3
+ text "surrounding_widget before"
4
+ widget Views::ClassLoadingSystemSpec::UnderscoreWidget
5
+ text "surrounding_widget after"
6
+ end
7
+ end
@@ -1,4 +1,8 @@
1
1
  class DevelopmentModeSystemSpecController < ApplicationController
2
+ def the_class_should_not_load
3
+ render :text => ::DevelopmentModeSystemSpec::ClassShouldNotLoad.name
4
+ end
5
+
2
6
  def reload_widget
3
7
  @datum = "one"
4
8
  end
@@ -1,4 +1,4 @@
1
- module ClassLoadingSystemSpec
1
+ module DevelopmentModeSystemSpec
2
2
  class ClassShouldNotLoad
3
3
  class << self
4
4
  def is_loaded
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortitude
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.9.0
5
5
  platform: java
6
6
  authors:
7
7
  - Andrew Geweke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -276,9 +276,11 @@ files:
276
276
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/autoload_one_widget_from_another.rb
277
277
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.html.rb
278
278
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.rb
279
- - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/class_should_not_load.rb
280
279
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/foo.rb
281
280
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/lib_views.rb
281
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/show_module_nesting.rb
282
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget.rb
283
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget_surrounding.rb
282
284
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_lib_widget_from_view_widget.rb
283
285
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_models_widget_from_view_widget.rb
284
286
  - spec/rails/templates/class_loading_system_spec/app/views/some_namespace/some_other_namespace/.git_keep
@@ -339,6 +341,7 @@ files:
339
341
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
340
342
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
341
343
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
344
+ - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/class_should_not_load.rb
342
345
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/form.rb
343
346
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
344
347
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb
@@ -621,9 +624,11 @@ test_files:
621
624
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/autoload_one_widget_from_another.rb
622
625
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.html.rb
623
626
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/bar.rb
624
- - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/class_should_not_load.rb
625
627
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/foo.rb
626
628
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/lib_views.rb
629
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/show_module_nesting.rb
630
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget.rb
631
+ - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/underscore_widget_surrounding.rb
627
632
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_lib_widget_from_view_widget.rb
628
633
  - spec/rails/templates/class_loading_system_spec/app/views/class_loading_system_spec/use_models_widget_from_view_widget.rb
629
634
  - spec/rails/templates/class_loading_system_spec/app/views/some_namespace/some_other_namespace/.git_keep
@@ -684,6 +689,7 @@ test_files:
684
689
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_formatting_test.rb
685
690
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_layout_test.rb
686
691
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_mailer/mailer_view_test.rb
692
+ - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/class_should_not_load.rb
687
693
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/form.rb
688
694
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_formatting_test.rb
689
695
  - spec/rails/templates/development_mode_system_spec/app/views/development_mode_system_spec/mailer_layout_test.rb