Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JRuby Support #79

Merged
merged 1 commit into from
Oct 16, 2015
Merged

Add JRuby Support #79

merged 1 commit into from
Oct 16, 2015

Conversation

brennovich
Copy link

In face of JRuby issue to a particular MRI behavior involving lexical
escope of cvars of duped classes, this commit changes the approach by
using instance vars without duping classes.

Note: Even though it's a JRuby issue
jruby/jruby#2988 (comment)
I decided to change Lotus implementation because of the complexity of
fixing it on JRuby side (second its core maintainers).

Ref. hanami/hanami#307

In face of JRuby issue to a particular MRI behavior involving lexical
escope of `cvar`s of duped classes, this commit changes the approach by
using instance vars without duping classes.

Note: Even though it's a JRuby issue
jruby/jruby#2988 (comment)
I decided to change Lotus implementation because of the complexity of
fixing it on JRuby side (second their core maintainers).

Ref. hanami/hanami#307
@brennovich
Copy link
Author

@jodosha @joneslee85 need you help, guys, to review this :)

@deepj
Copy link

deepj commented Oct 12, 2015

Just for a record: The same issue has Rubinius as well. This is a specific MRI behaviour which is not covered by any specification.

@brennovich
Copy link
Author

Thanks @deepj I think this fact scores on change the implementation :)

extend Rendering.dup
extend Inheritable
extend Dsl
extend Rendering
extend Escape.dup

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this dup be removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guy doesn't need it because it doesn't have class variables, so no issue with scope ;)

@AlfonsoUceda
Copy link

test passes it's a good starting point, AFAIK I think is ok but removing dup and class I dont the new behaviour. @jodosha could you take a look?

@AlfonsoUceda AlfonsoUceda added this to the v0.4.5 milestone Oct 12, 2015
@brennovich
Copy link
Author

@AlfonsoUceda I think that is a similar behavior, instead of maintaining cvars and duping classes we're keeping instance vars with new instances. Be aware that the objects are still being frozen and they still keep using the same reference like the previous approach

@runlevel5
Copy link
Member

👍 to me

cc @jodosha

@AlfonsoUceda
Copy link

👍

@brennovich
Copy link
Author

I can benchmark it :)

Do you guys have any "official" benchmark strategy?

@runlevel5
Copy link
Member

@brennovich please talk to @jodosha on Gitter, I believe he's already had a set of benchmark scripts

@brennovich
Copy link
Author

Well, discussing with @jodosha he told me about his concerns about the Lotus::View context when dealing with multiple applications and he tip me some tricks of how to test it :)

Setup

lotus new bookshelf --lotus-head=true
cd bookshelf
vim Gemfile # point lotus-view to your branch
bundle
bundle exec lotus generate app admin

Current Implementation

  1. bundle exec lotus console

Lotus::View does not even initialize because cvars lexical scope issue with JRuby

Lotus::View::Rendering::MissingTemplateLayoutError: Can't find layout template 'Admin::Views::ApplicationLayout'
               prepare! at /home/brennovich/.rbenv/versions/jruby-9.0.1.0/lib/ruby/gems/shared/bundler/gems/view-c57b8db8dc7
9/lib/lotus/view/rendering/layout_registry.rb:60
             initialize at /home/brennovich/.rbenv/versions/jruby-9.0.1.0/lib/ruby/gems/shared/bundler/gems/view-c57b8db8dc7
9/lib/lotus/view/rendering/layout_registry.rb:34
               registry at /home/brennovich/.rbenv/versions/jruby-9.0.1.0/lib/ruby/gems/shared/bundler/gems/view-c57b8db8dc7
9/lib/lotus/layout.rb:61
                  load! at /home/brennovich/.rbenv/versions/jruby-9.0.1.0/lib/ruby/gems/shared/bundler/gems/view-c57b8db8dc7
9/lib/lotus/layout.rb:103
         block in load! at /home/brennovich/.rbenv/versions/jruby-9.0.1.0/lib/ruby/gems/shared/bundler/gems/view-c57b8db8dc7
9/lib/lotus/view/configuration.rb:364

This branch

  1. First I changed default templates relative path of Web app to templates_web (Admin has the default templates)
  2. bundle exec lotus console

We can see that configurations keep themselves valid without leaking (look at te renderer's templates config):

irb(main):009:0> Web::Application.new
=> #<Web::Application:0x10db6131  @renderer=#<Lotus::RenderingPolicy:0x4730e0f0 @templates=<Pathname:/home/brennovich/code/bookshelf/apps/
web/templates_web>, @view_pattern="Views::%{controller}::%{action}", @namespace=Web, @controller_pattern=/Controllers::(?<co
ntroller>(.*))::(?<action>(.*))/>>
irb(main):010:0> Admin::Application
=> Admin::Application
irb(main):011:0> Admin::Application.new
=> #<Admin::Application:0x37c41ec0  @renderer=#<Lotus::RenderingPolicy:0x5399f6c5 @templates=<Pathname:/home/brennovich/code/bookshelf/apps/
admin/templates>, @view_pattern="Views::%{controller}::%{action}", @namespace=Admin, @controller_pattern=/Controllers::(?<co
ntroller>(.*))::(?<action>(.*))/>>
irb(main):012:0> Web::Application.new
=> #<Web::Application:0x76464795 @renderer=#<Lotus::RenderingPolicy:0x48f4713c @templates=<Pathname:/home/brennovich/code/bookshelf/apps/
web/templates_web>, @view_pattern="Views::%{controller}::%{action}", @namespace=Web, @controller_pattern=/Controllers::(?<co
ntroller>(.*))::(?<action>(.*))/>>

@@ -16,13 +24,11 @@ rvm:
- 2.2.1
- 2.2.2
- 2.2.3
- jruby-9000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please test against newer version 9.0.1.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using 9.0.1.0 on my machine, but when I wrote this PR rvm wasn't with this version available :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! I'll open a PR with adding this ;)

@runlevel5
Copy link
Member

@brennovich looks good, please rebase

@jodosha
Copy link
Member

jodosha commented Oct 16, 2015

@brennovich @joneslee85 I manually tested and can confirm this works 👍 I'll take care of merge it. 👍

@jodosha jodosha merged commit de7fc47 into hanami:master Oct 16, 2015
jodosha added a commit that referenced this pull request Oct 16, 2015
@jodosha jodosha self-assigned this Oct 16, 2015
@brennovich
Copy link
Author

Thanks for testing it @jodosha :)

@brennovich brennovich deleted the add-jruby-support branch October 16, 2015 12:06
jodosha added a commit that referenced this pull request Oct 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants