Skip to content

Commit

Permalink
Upgrade Ruby Next
Browse files Browse the repository at this point in the history
Use Hash shorthand notation
  • Loading branch information
palkan committed Sep 2, 2020
1 parent 936dacf commit d4ee4c6
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -11,7 +11,7 @@ gem 'redis', '~> 4.0'
gem 'anycable-rails', '~> 1.0.0'

gem 'bootsnap', '>= 1.4.2', require: false
gem 'ruby-next', '>= 0.9.2', require: false
gem 'ruby-next', '>= 0.10.0', require: false

gem 'nanoid'
# We only need controllers integration
Expand Down
95 changes: 54 additions & 41 deletions Gemfile.lock
Expand Up @@ -62,6 +62,10 @@ GEM
memoizable (~> 0.4.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
anima (0.3.1)
abstract_type (~> 0.0.7)
adamantium (~> 0.2)
equalizer (~> 0.0.11)
anycable (1.0.1)
anyway_config (>= 1.4.2)
grpc (~> 1.17)
Expand All @@ -71,11 +75,11 @@ GEM
anyway_config (2.0.6)
ruby-next-core (>= 0.8.0)
ast (2.4.1)
bootsnap (1.4.6)
bootsnap (1.4.8)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.32.1)
capybara (3.33.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -85,40 +89,40 @@ GEM
xpath (~> 3.2)
childprocess (3.0.0)
cliver (0.3.2)
coderay (1.1.2)
coderay (1.1.3)
concord (0.1.5)
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.1.6)
concurrent-ruby (1.1.7)
crass (1.0.6)
cuprite (0.10)
cuprite (0.11)
capybara (>= 2.1, < 4)
ferrum (~> 0.8.0)
diff-lcs (1.4.1)
ferrum (~> 0.9.0)
diff-lcs (1.4.4)
equalizer (0.0.11)
erubi (1.9.0)
ferrum (0.8)
addressable (~> 2.6)
ferrum (0.9)
addressable (~> 2.5)
cliver (~> 0.3)
concurrent-ruby (~> 1.1)
websocket-driver (>= 0.6, < 0.8)
ffi (1.12.2)
ffi (1.13.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-protobuf (3.12.2)
google-protobuf (3.13.0)
googleapis-common-protos-types (1.0.5)
google-protobuf (~> 3.11)
grpc (1.30.0)
grpc (1.31.1)
google-protobuf (~> 3.12)
googleapis-common-protos-types (~> 1.0)
i18n (1.8.3)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
jaro_winkler (1.5.4)
listen (3.2.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.6.0)
loofah (2.7.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
Expand All @@ -131,13 +135,20 @@ GEM
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
minitest (5.14.2)
mprelude (0.1.0)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
concord (~> 0.1.5)
equalizer (~> 0.0.9)
ice_nine (~> 0.11.1)
procto (~> 0.0.2)
msgpack (1.3.3)
nanoid (2.0.0)
nio4r (2.5.2)
nokogiri (1.10.9)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
pg (1.2.3)
Expand All @@ -150,8 +161,8 @@ GEM
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.4)
puma (4.3.3)
public_suffix (4.0.6)
puma (4.3.5)
nio4r (~> 2.0)
rack (2.2.3)
rack-proxy (0.6.5)
Expand Down Expand Up @@ -186,29 +197,29 @@ GEM
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (13.0.1)
rb-fsevent (0.10.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.1.3)
regexp_parser (1.7.0)
redis (4.2.1)
regexp_parser (1.7.1)
rexml (3.2.4)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (4.0.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.2)
rspec-support (3.9.3)
rubocop (0.80.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand All @@ -223,15 +234,15 @@ GEM
activesupport
rack (>= 1.1)
rubocop (>= 0.72.0)
rubocop-rspec (1.39.0)
rubocop-rspec (1.41.0)
rubocop (>= 0.68.1)
ruby-next (0.9.2)
ruby-next-core (= 0.9.2)
ruby-next-parser (>= 2.8.0.7)
unparser (>= 0.4.7)
ruby-next-core (0.9.2)
ruby-next-parser (2.8.0.7)
parser (>= 2.7.1.4)
ruby-next (0.10.0)
ruby-next-core (= 0.10.0)
ruby-next-parser (>= 3.0.0.0)
unparser (>= 0.4.8)
ruby-next-core (0.10.0)
ruby-next-parser (3.0.0.0)
parser (>= 2.7.0.5)
ruby-progressbar (1.10.1)
rubyzip (2.3.0)
selenium-webdriver (3.142.7)
Expand All @@ -247,7 +258,7 @@ GEM
standard (0.2.5)
rubocop (~> 0.80.1)
rubocop-performance (~> 1.5.2)
test-prof (0.11.3)
test-prof (0.12.1)
thor (1.0.1)
thread_safe (0.3.6)
turbolinks (5.2.1)
Expand All @@ -256,24 +267,26 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.6.1)
unparser (0.4.7)
unparser (0.4.8)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
anima (~> 0.3.1)
concord (~> 0.1.5)
diff-lcs (~> 1.3)
equalizer (~> 0.0.9)
mprelude (~> 0.1.0)
parser (>= 2.6.5)
procto (~> 0.0.2)
webpacker (4.2.2)
webpacker (4.3.0)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket-driver (0.7.2)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.3.0)
zeitwerk (2.4.0)

PLATFORMS
ruby
Expand All @@ -294,7 +307,7 @@ DEPENDENCIES
rspec-rails (~> 4.0.0)
rubocop-rails
rubocop-rspec
ruby-next (>= 0.9.2)
ruby-next (>= 0.10.0)
selenium-webdriver
standard (~> 0.2.0)
test-prof
Expand Down
7 changes: 2 additions & 5 deletions app/channels/application_cable/channel.rb
Expand Up @@ -2,11 +2,8 @@

module ApplicationCable
class Channel < ActionCable::Channel::Base
def html(template, **locals)
ApplicationController.render(
partial: template,
locals: locals
)
def html(partial, **locals)
ApplicationController.render(**{partial, locals})
end
end
end
3 changes: 2 additions & 1 deletion app/channels/chat_channel.rb
Expand Up @@ -12,11 +12,12 @@ def subscribed

def speak(data)
message = data.fetch("message")
name = user.name

broadcast_to(
workspace,
action: "newMessage",
html: html("chats/message", message: message, name: user.name),
html: html("chats/message", **{message, name}),
author_id: user.id
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/authenticated.rb
Expand Up @@ -30,7 +30,7 @@ def login_from_cookie
return unless cookies[:uid]

name, id = cookies[:uid].split("/")
User.new(name: name, id: id).tap do |user|
User.new({name, id}).tap do |user|
# store in session
commit_user_to_session! user
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/items_controller.rb
Expand Up @@ -71,7 +71,7 @@ def set_item

def broadcast_new_item
return if item.errors.any?
ListChannel.broadcast_to list, type: "created", html: render_to_string(partial: "items/item", layout: false, locals: {item: item})
ListChannel.broadcast_to list, type: "created", html: render_to_string(partial: "items/item", layout: false, locals: {item})
end

def broadcast_changes
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lists_controller.rb
Expand Up @@ -44,7 +44,7 @@ def set_list

def broadcast_new_list
return if list.errors.any?
WorkspaceChannel.broadcast_to workspace, type: "newList", html: render_to_string(partial: "lists/list", layout: false, locals: {list: list})
WorkspaceChannel.broadcast_to workspace, type: "newList", html: render_to_string(partial: "lists/list", layout: false, locals: {list})
end

def broadcast_changes
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/workspaces_controller.rb
Expand Up @@ -12,11 +12,11 @@ def create
workspace = Workspace.new(workspace_params)
if workspace.save
# populate demo data
Workspaces::CreateDemo.call(workspace: workspace)
Workspaces::CreateDemo.call(**{workspace})
redirect_to workspace_path(workspace), notice: "Welcome to your new workspace!"
else
flash.now[:alert] = "Failed to create a workspace: #{workspace.errors.full_messages.join(";")}"
render :new, locals: {workspace: workspace}
render :new, locals: {workspace}
end
end

Expand All @@ -25,7 +25,7 @@ def index

def show
workspace = Workspace.find_by!(public_id: params[:id])
render locals: {workspace: workspace}
render locals: {workspace}
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -10,6 +10,6 @@ class User
attribute :id, :string

class << self
def generate(name) = new(name: name, id: Nanoid.generate(size: 5))
def generate(name) = new({name, id: Nanoid.generate(size: 5)})
end
end
4 changes: 2 additions & 2 deletions app/services/workspaces/create_demo.rb
Expand Up @@ -3,10 +3,10 @@
module Workspaces
module CreateDemo
class << self
def call(name: "Demo Workspace", id: nil, workspace: nil)
def call(name: "Demo Workspace", public_id: nil, workspace: nil)
ActiveRecord::Base.transaction do
# We can use the existing workspace to populate demo data
demo = workspace || Workspace.create!(name: name, public_id: id)
demo = workspace || Workspace.create!({name, public_id})

# First list
demo.lists.create(name: "Migrate to AnyCable").tap do |list|
Expand Down
2 changes: 2 additions & 0 deletions config/boot.rb
Expand Up @@ -4,9 +4,11 @@

require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" # Speed up boot time by caching expensive operations.

# Use edge Ruby syntax
require "ruby-next/language"
RubyNext::Language.mode = :rewrite

require "ruby-next/language/edge"
require "ruby-next/language/proposed"
require "ruby-next/language/bootsnap"
2 changes: 1 addition & 1 deletion db/seeds.rb
Expand Up @@ -2,5 +2,5 @@

ActiveRecord::Base.transaction do
# create demo workspace
_demo = Workspaces::CreateDemo.call(id: "demo")
_demo = Workspaces::CreateDemo.call(public_id: "demo")
end

0 comments on commit d4ee4c6

Please sign in to comment.