Skip to content

Commit

Permalink
Add JRuby Support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brennovich committed Oct 12, 2015
1 parent 8d0adf2 commit de7fc47
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 12 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
Expand Up @@ -2,6 +2,14 @@ language: ruby
script: 'bundle exec rake test:coverage'
sudo: false
cache: bundler
install: true
env:
global:
- JRUBY_OPTS=--dev
script:
- 'if [[ "$TRAVIS_RUBY_VERSION" =~ "jruby" ]]; then rvm get head && rvm reload && rvm use --install $TRAVIS_RUBY_VERSION; fi'
- 'bundle install'
- 'bundle exec rake test:coverage'
rvm:
- 2.0.0
- 2.1.0
Expand All @@ -16,13 +24,11 @@ rvm:
- 2.2.1
- 2.2.2
- 2.2.3
- jruby-9000
- jruby-head
- rbx-2

matrix:
include:
- rvm: jruby-head
- rvm: jruby-9000
allow_failures:
- rvm: rbx-2
- rvm: jruby-head
- rvm: jruby-9000
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -3,6 +3,7 @@ gemspec

unless ENV['TRAVIS']
gem 'byebug', require: false, platforms: :mri if RUBY_VERSION >= '2.1.0'
gem 'pry', require: false, platforms: :jruby
gem 'yard', require: false
end

Expand Down
6 changes: 3 additions & 3 deletions lib/lotus/view.rb
Expand Up @@ -268,9 +268,9 @@ def self.included(base)
conf.add_view(base)

base.class_eval do
extend Inheritable.dup
extend Dsl.dup
extend Rendering.dup
extend Inheritable
extend Dsl
extend Rendering
extend Escape.dup

include Utils::ClassAttribute
Expand Down
4 changes: 2 additions & 2 deletions lib/lotus/view/dsl.rb
Expand Up @@ -205,9 +205,9 @@ def format(value = nil)
# Bookshelf::Api::Views::Books::Index.template # => 'books/index'
def template(value = nil)
if value.nil?
@@template ||= Rendering::TemplateName.new(name, configuration.namespace).to_s
@template ||= Rendering::TemplateName.new(name, configuration.namespace).to_s
else
@@template = value
@template = value
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/lotus/view/inheritable.rb
Expand Up @@ -27,7 +27,7 @@ def inherited(base)
# @api private
# @since 0.1.0
def subclasses
@@subclasses ||= Set.new
@subclasses ||= Set.new
end

protected
Expand All @@ -47,7 +47,7 @@ def load!
# @api private
# @since 0.1.0
def views
@@views ||= [ self ] + subclasses.to_a
@views ||= [ self ] + subclasses.to_a
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/view/rendering.rb
Expand Up @@ -258,7 +258,7 @@ def load!
#
# @see Lotus::View::Rendering::Registry
def registry
@@registry ||= Registry.new(self)
@registry ||= Registry.new(self)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/fixtures.rb
Expand Up @@ -209,6 +209,7 @@ def map

class IndexView
include Lotus::View

layout :application
end

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
@@ -1,5 +1,6 @@
require 'rubygems'
require 'bundler/setup'
require 'tilt/erb'

if ENV['COVERAGE'] == 'true'
require 'simplecov'
Expand Down

0 comments on commit de7fc47

Please sign in to comment.