Skip to content

Commit

Permalink
Fixing last errors in Ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Oct 31, 2021
1 parent 55344d4 commit 724cc59
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 68 deletions.
67 changes: 39 additions & 28 deletions decidim-core/lib/gem_overrides/rectify/command.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
# frozen_string_literal: true

module Rectify
class Presenter
def method_missing(method_name, ...)
if view_context.respond_to?(method_name)
view_context.send(method_name, ...)
else
super
if defined?(Rectify) && RUBY_VERSION >= "3.0.0"
unless Rectify::VERSION == "0.13.0"
msg = %(
Rectify v 0.13.0 library has some methods overridden in #{__FILE__} to support Ruby 3 upgrade.
At the time when this message has been written there are no changes in gem repo that may fix this.
You have installed version: #{Rectify::VERSION}. Please check whether the upgrades are addressing or not those issues.
)
raise msg
end

module Rectify
class Presenter
def method_missing(method_name, ...)
if view_context.respond_to?(method_name)
view_context.send(method_name, ...)
else
super
end
end
end

def respond_to_missing?(method_name, include_private = false)
view_context.respond_to?(method_name, include_private)
def respond_to_missing?(method_name, include_private = false)
view_context.respond_to?(method_name, include_private)
end
end
end

class Command
def self.call(*args, **kwargs, &block)
event_recorder = EventRecorder.new
class Command
def self.call(*args, **kwargs, &block)
event_recorder = EventRecorder.new

command = new(*args, **kwargs)
command.subscribe(event_recorder)
command.evaluate(&block) if block_given?
command.call
command = new(*args, **kwargs)
command.subscribe(event_recorder)
command.evaluate(&block) if block_given?
command.call

event_recorder.events
end
event_recorder.events
end

def method_missing(method_name, ...)
if @caller.respond_to?(method_name, true)
@caller.send(method_name, ...)
else
super
def method_missing(method_name, ...)
if @caller.respond_to?(method_name, true)
@caller.send(method_name, ...)
else
super
end
end
end

def respond_to_missing?(method_name, include_private = false)
@caller.respond_to?(method_name, include_private)
def respond_to_missing?(method_name, include_private = false)
@caller.respond_to?(method_name, include_private)
end
end
end
end
2 changes: 1 addition & 1 deletion decidim-elections/lib/decidim/votings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require "decidim/votings/census_engine"
require "decidim/votings/census_admin_engine"
require "rack/attack"

require_relative "../gem_overrides/graphlient/client"
module Decidim
# This namespace holds the logic of the `Votings` space.
module Votings
Expand Down
35 changes: 35 additions & 0 deletions decidim-elections/lib/gem_overrides/graphlient/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

# The ruby 3 requires splat on the query_params. The GraphLient gem fixes this in version 0.5.0, yet the
# decidim-bulletin-board is using 0.4.0
if defined?(Graphlient) && RUBY_VERSION >= "3.0.0"
unless Graphlient::VERSION == "0.4.0"
msg = %(
Graphlient library has some methods overridden in #{__FILE__} to support Ruby 3 upgrade.
It is known that 0.5.0 version is already fixing the issue.
You have installed version: #{Graphlient::VERSION}
)
raise msg
end

# rubocop:disable Layout/EmptyLineAfterGuardClause
module Graphlient
class Client
def execute(query, variables = nil)
query_params = {}
query_params[:context] = @options if @options
query_params[:variables] = variables if variables
query = client.parse(query) if query.is_a?(String)
rc = client.query(query, **query_params)
raise Graphlient::Errors::GraphQLError, rc if rc.errors.any?
# see https://github.com/github/graphql-client/pull/132
# see https://github.com/exAspArk/graphql-errors/issues/2
raise Graphlient::Errors::ExecutionError, rc if errors_in_result?(rc)
rc
rescue GraphQL::Client::Error => e
raise Graphlient::Errors::ClientError, e.message
end
end
end
# rubocop:enable Layout/EmptyLineAfterGuardClause
end
2 changes: 1 addition & 1 deletion decidim-elections/spec/system/votings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it "redirects to the voting" do
expect(page).to have_content(translated(title: single_voting))
expect(page).to have_content(translated(single_voting.title))
expect(page).not_to have_selector("#votings")
end
end
Expand Down
95 changes: 57 additions & 38 deletions decidim-initiatives/lib/gem_overrides/origami/string.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
# frozen_string_literal: true
#

# https://github.com/gdelugre/origami/issues/80
module Origami
class Date < LiteralString
def self.parse(str) #:nodoc:
raise InvalidDateError, "Not a valid Date string" unless str =~ REGEXP_TOKEN

date =
{
year: $~['year'].to_i
}

date[:month] = $~['month'].to_i if $~['month']
date[:day] = $~['day'].to_i if $~['day']
date[:hour] = $~['hour'].to_i if $~['hour']
date[:min] = $~['min'].to_i if $~['min']
date[:sec] = $~['sec'].to_i if $~['sec']

if %w[+ -].include?($~['ut'])
utc_offset = $~['ut_hour_off'].to_i * 3600 + $~['ut_min_off'].to_i * 60
utc_offset = -utc_offset if $~['ut'] == '-'

date[:utc_offset] = utc_offset
end

Origami::Date.new(**date)
end
# The ruby 3 requires splat on the query_params. The GraphLient gem fixes this in version 0.5.0, yet the
# decidim-bulletin-board is using 0.4.0

if defined?(Origami) && RUBY_VERSION >= "3.0.0"
unless Origami::VERSION == "2.1.0"
msg = %(
Origami v 2.1.0 library has some methods overridden in #{__FILE__} to support Ruby 3 upgrade.
There are no recent changes on the gem's repo, so a fix is not forseen at the time when this message has been written
You have installed version: #{Origami::VERSION}. Please check whether the upgrades are addressing or not those issues.
)
raise msg
end
# rubocop:disable Style/SpecialGlobalVars
# rubocop:disable Style/StringLiterals
# rubocop:disable Style/PercentLiteralDelimiters
module Origami
class Date < LiteralString
def self.parse(str) #:nodoc:
raise InvalidDateError, "Not a valid Date string" unless str =~ REGEXP_TOKEN

date =
{
year: $~['year'].to_i
}

date[:month] = $~['month'].to_i if $~['month']
date[:day] = $~['day'].to_i if $~['day']
date[:hour] = $~['hour'].to_i if $~['hour']
date[:min] = $~['min'].to_i if $~['min']
date[:sec] = $~['sec'].to_i if $~['sec']

def self.now
now = Time.now.utc
if %w[+ -].include?($~['ut'])
utc_offset = $~['ut_hour_off'].to_i * 3600 + $~['ut_min_off'].to_i * 60
utc_offset = -utc_offset if $~['ut'] == '-'

date =
{
year: now.strftime("%Y").to_i,
month: now.strftime("%m").to_i,
day: now.strftime("%d").to_i,
hour: now.strftime("%H").to_i,
min: now.strftime("%M").to_i,
sec: now.strftime("%S").to_i,
utc_offset: now.utc_offset
}
date[:utc_offset] = utc_offset
end

Origami::Date.new(**date)
Origami::Date.new(**date)
end

def self.now
now = Time.now.utc

date =
{
year: now.strftime("%Y").to_i,
month: now.strftime("%m").to_i,
day: now.strftime("%d").to_i,
hour: now.strftime("%H").to_i,
min: now.strftime("%M").to_i,
sec: now.strftime("%S").to_i,
utc_offset: now.utc_offset
}

Origami::Date.new(**date)
end
end
end
# rubocop:enable Style/StringLiterals
# rubocop:enable Style/SpecialGlobalVars
# rubocop:enable Style/PercentLiteralDelimiters
end

0 comments on commit 724cc59

Please sign in to comment.