Skip to content

Commit

Permalink
Address rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed Nov 20, 2024
1 parent 7577b38 commit 9e0a67e
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 38 deletions.
12 changes: 5 additions & 7 deletions examples/rails/bin/yarn
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
warn "Yarn executable was not detected in the system."
warn "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
warn "Yarn executable was not detected in the system."
warn "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
2 changes: 1 addition & 1 deletion examples/rails/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Expand Down
6 changes: 3 additions & 3 deletions examples/rails/config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
port ENV.fetch("PORT", 3000)

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
environment ENV.fetch("RAILS_ENV", "development")

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def layout_locals(locals)

# @api private
def layout?
!!config.layout # rubocop:disable Style/DoubleNegation
!!config.layout
end
end
end
14 changes: 6 additions & 8 deletions lib/dry/view/exposure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def input_keys
end

def for_layout?
options.fetch(:layout) { false }
options.fetch(:layout, false)
end

def decorate?
options.fetch(:decorate) { true }
options.fetch(:decorate, true)
end

def private?
options.fetch(:private) { false }
options.fetch(:private, false)
end

def default_value
Expand All @@ -84,12 +84,10 @@ def call_proc(input, locals)
else
object.instance_exec(*args, &proc)
end
elsif proc.is_a?(Method)
proc.(*args, **keywords)
else
if proc.is_a?(Method)
proc.(*args, **keywords)
else
object.instance_exec(*args, **keywords, &proc)
end
object.instance_exec(*args, **keywords, &proc)
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/dry/view/exposures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def bind(obj)
end

def call(input)
# rubocop:disable Style/MultilineBlockChain
tsort.each_with_object({}) { |name, memo|
next unless (exposure = self[name])

Expand Down
7 changes: 2 additions & 5 deletions lib/dry/view/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ def self.part_name(inflector)
#
# @api public
def initialize(
render_env: RenderEnvironmentMissing.new,
name: self.class.part_name(render_env.inflector),
value:
value:, render_env: RenderEnvironmentMissing.new,
name: self.class.part_name(render_env.inflector)
)
@_name = name
@_value = value
Expand Down Expand Up @@ -126,11 +125,9 @@ def _context
# @return [String] rendered partial
#
# @api public
# rubocop:disable Naming/UncommunicativeMethodParamName
def _render(partial_name, as: _name, **locals, &block)
_render_env.partial(partial_name, _render_env.scope({as => self}.merge(locals)), &block)
end
# rubocop:enable Naming/UncommunicativeMethodParamName

# Builds a new scope with the part included in its locals.
#
Expand Down
4 changes: 1 addition & 3 deletions lib/dry/view/part_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def part_class(name:, fallback_class: Part, **options)
end
end

# rubocop:disable Metrics/PerceivedComplexity
def resolve_part_class(name:, fallback_class:)
return fallback_class unless namespace

Expand All @@ -117,7 +116,7 @@ def resolve_part_class(name:, fallback_class:)
# Give autoloaders a chance to act
begin
klass = namespace.const_get(name)
rescue NameError # rubocop:disable Lint/HandleExceptions
rescue NameError
end

if !klass && namespace.const_defined?(name, false)
Expand All @@ -130,7 +129,6 @@ def resolve_part_class(name:, fallback_class:)
fallback_class
end
end
# rubocop:enable Metrics/PerceivedComplexity

def inflector
render_env.inflector
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/view/scope_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def resolve_scope_class(name:)
# Give autoloaders a chance to act
begin
klass = namespace.const_get(name)
rescue NameError # rubocop:disable Lint/HandleExceptions
rescue NameError
end

if !klass && namespace.const_defined?(name, false)
Expand Down
1 change: 1 addition & 0 deletions spec/integration/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def [](path)

class Context < Dry::View::Context
attr_reader :assets

decorate :assets

def initialize(assets:, **options)
Expand Down
10 changes: 5 additions & 5 deletions spec/integration/scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def hello
module Test::Scopes
class Greeting < Dry::View::Scope
def greeting
_locals[:greeting].upcase + "!"
"#{_locals[:greeting].upcase}!"
end
end
end
Expand All @@ -62,7 +62,7 @@ def greeting
module Test::Scopes
class Greeting < Dry::View::Scope
def greeting
_locals[:greeting].upcase + "!"
"#{_locals[:greeting].upcase}!"
end
end
end
Expand All @@ -89,7 +89,7 @@ def greeting
module Test::Scopes
class Greeting < Dry::View::Scope
def greeting
_locals[:greeting].upcase + "!"
"#{_locals[:greeting].upcase}!"
end
end
end
Expand All @@ -108,7 +108,7 @@ def greeting
module Test::Scopes
class Greeting < Dry::View::Scope
def greeting
_locals.fetch(:greeting) { "Howdy" }
_locals.fetch(:greeting, "Howdy")
end
end
end
Expand All @@ -135,7 +135,7 @@ def greeting
module Test::Scopes
class Greeting < Dry::View::Scope
def greeting
_locals[:greeting] + "!"
"#{_locals[:greeting]}!"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/testing/testing_parts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
specify "Parts can be unit tested without name or rendering (for testing methods that don't require them)" do
part_class = Class.new(Dry::View::Part) do
def breaking_news_title
title + "!"
"#{title}!"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def assets

klass.setting :paths, default: SPEC_ROOT.join("fixtures/templates")
klass.setting :layout, default: "app"
klass.setting :formats, default: { html: :slim }
klass.setting :formats, default: {html: :slim}

klass
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/exposure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def hello(input)

describe "#dependency_names" do
context "proc provided" do
let(:proc) { -> input, foo, bar { "hi" } } # rubocop:disable Lint/UnusedBlockArgument
let(:proc) { -> input, foo, bar { "hi" } }

it "returns an array of exposure dependencies derived from the proc's argument names" do
expect(exposure.dependency_names).to eql [:input, :foo, :bar]
Expand Down

0 comments on commit 9e0a67e

Please sign in to comment.