Skip to content

Commit

Permalink
Modify keyword arguments for Ruby 2.0 compat
Browse files Browse the repository at this point in the history
Required keyword arguments were introduced in Ruby 2.1, but can be emulated in 2.0 by using a default value that raises an ArgumentError
  • Loading branch information
bbonamin committed Dec 20, 2016
1 parent 6411a3b commit 52e2915
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@ def props_string(props)

# Returns Array [0]: html, [1]: script to console log
# NOTE, these are NOT html_safe!
def server_rendered_react_component_html(props, react_component_name, dom_id,
prerender:, trace:, raise_on_prerender_error:)
def server_rendered_react_component_html(
props, react_component_name, dom_id, prerender: raise(ArgumentError, "prerender is required"),
trace: raise(ArgumentError, "trace is required"),
raise_on_prerender_error: raise(ArgumentError, "raise_on_prerender_error is required")
)
return { "html" => "", "consoleReplayScript" => "" } unless prerender

# On server `location` option is added (`location = request.fullpath`)
Expand Down Expand Up @@ -342,7 +345,7 @@ def initialize_redux_stores
# This is the definitive list of the default values used for the rails_context, which is the
# second parameter passed to both component and store generator functions.
# rubocop:disable Metrics/AbcSize
def rails_context(server_side:)
def rails_context(server_side: raise(ArgumentError, "server_side is required"))
@rails_context ||= begin
result = {
inMailer: in_mailer?,
Expand Down
5 changes: 4 additions & 1 deletion lib/react_on_rails/react_component/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class Options
NO_PROPS = {}.freeze
HIDDEN = "display:none".freeze

def initialize(name:, options:)
def initialize(
name: raise(ArgumentError, "name is required"),
options: raise(ArgumentError, "options are required")
)
@name = name
@options = options
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class WebpackAssetsStatusChecker
# client_dir is typically /client, where all client files go
attr_reader :client_dir, :generated_assets_dir

def initialize(generated_assets_dir:, client_dir:, webpack_generated_files:)
def initialize(
generated_assets_dir: raise(ArgumentError, "generated_assets_dir is required"),
client_dir: raise(ArgumentError, "client_dir is required"),
webpack_generated_files: raise(ArgumentError, "webpack_generated_files is required")
)
@generated_assets_dir = generated_assets_dir
@client_dir = client_dir
@webpack_generated_files = webpack_generated_files
Expand Down

0 comments on commit 52e2915

Please sign in to comment.