Skip to content

Commit

Permalink
Merge pull request #16 from julianrubisch/rails-7-1-support
Browse files Browse the repository at this point in the history
Rails 7 1 support
  • Loading branch information
julianrubisch authored Mar 28, 2024
2 parents ee071d2 + 9043b80 commit bb74127
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [2.7.2, 3.0.3, 3.1.0]
rails-version: ['6_0', '6_1', '7_0']
ruby-version: [3.1.4, 3.2.3, 3.3.0]
rails-version: ['6_0', '6_1', '7_0', '7_1']
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails-version }}.gemfile
steps:
Expand Down
4 changes: 4 additions & 0 deletions app/channels/cubism/presence_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ def unsubscribed

def appear
resource.set_present_users_for_scope(resource.present_users_for_scope(scope).add(user.id), scope) if scope
rescue ActiveRecord::RecordNotFound
# do nothing if the user wasn't found
end

def disappear
resource.set_present_users_for_scope(resource.present_users_for_scope(scope).delete(user.id), scope) if scope
rescue ActiveRecord::RecordNotFound
# do nothing if the user wasn't found
end

private
Expand Down
9 changes: 9 additions & 0 deletions gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "pry", group: [:development, :test]
gem "rails", "7.1.3.2"
gem "sqlite3", "~> 1.4"

gemspec path: "../"
13 changes: 12 additions & 1 deletion lib/cubism/preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def process
begin
do_parse
rescue NameError
# TODO we need a better way to handle this, leads to false negatives
# we ignore any name errors from unset instance variables or local assigns here
end

Expand All @@ -23,11 +24,21 @@ def process
private

def do_parse
ActionView::Template::Handlers::ERB::Erubi.new(@source).evaluate(@view_context)
erubi = ActionView::Template::Handlers::ERB::Erubi.new(@source)

evaluate_view(erubi, @view_context)
rescue SyntaxError
end_at_end = /(<%\s+end\s+%>)\z/.match(@source)
@source = end_at_end ? @source[..-(end_at_end[0].length + 1)] : @source[..-2]
do_parse
end

def evaluate_view(erubi, view_context)
view = Class.new(ActionView::Base) {
include view_context._routes.url_helpers
class_eval("define_method(:_template) { |local_assigns, output_buffer| #{erubi.src} }", erubi.filename.nil? ? "(erubi)" : erubi.filename, 0)
}.empty
view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
end
end
end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@minthesize/cubism",
"version": "0.1.0",
"version": "0.1.1",
"description": "Lightweight Resource-Based Presence Solution with CableReady.",
"main": "./dist/cubism.umd.min.js",
"module": "./dist/cubism.min.js",
Expand Down

0 comments on commit bb74127

Please sign in to comment.