Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/concerns/view_component/preview_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module PreviewActions
around_action :set_locale, only: :previews
before_action :require_local!, unless: :show_previews?

content_security_policy(false) if respond_to?(:content_security_policy)
content_security_policy(false)

# Including helpers here ensures that we're loading the
# latest version of helpers if code-reloading is enabled
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ nav_order: 5

*Reegan Viljoen*

* Removed `respond_to?` methods from three files.

*Tiago Menegaz*

## 3.21.0

* Updates testing docs to include an example of how to use with RSpec.
Expand Down
7 changes: 4 additions & 3 deletions lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def method_missing(method_name, *args) # rubocop:disable Style/MissingRespondToM
super
rescue => e # rubocop:disable Style/RescueStandardError
e.set_backtrace e.backtrace.tap(&:shift)
raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.respond_to?(method_name)
raise e, <<~MESSAGE.chomp if view_context && e.is_a?(NameError) && helpers.methods.include?(method_name.to_sym)
#{e.message}

You may be trying to call a method provided as a view helper. Did you mean `helpers.#{method_name}'?
Expand Down Expand Up @@ -287,7 +287,8 @@ def request
#
# @private
def __vc_request
@__vc_request ||= controller.request if controller.respond_to?(:request)
@__vc_request ||= controller.request
rescue NoMethodError
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this change goes against this project's code style? 🤔

end

# The content passed to the component instance as a block.
Expand Down Expand Up @@ -678,7 +679,7 @@ def splatted_keyword_argument_present?
end

def initialize_parameter_names
return attribute_names.map(&:to_sym) if respond_to?(:attribute_names)
return attribute_names.map(&:to_sym) if method_defined?(:attribute_names)

initialize_parameters.map(&:last)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def initialize(component, object, spacer_component, **options)
end

def collection_variable(object)
if object.respond_to?(:to_ary)
if object.class.method_defined?(:to_ary)
object.to_ary
else
raise InvalidCollectionArgumentError
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/slotable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def renders_many(slot_name, callable = nil)

define_method :"with_#{slot_name}" do |collection_args = nil, &block|
collection_args.map do |args|
if args.respond_to?(:to_hash)
if args.class.method_defined?(:to_hash)
set_slot(slot_name, nil, **args, &block)
else
set_slot(slot_name, nil, *args, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/slotable_default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def get_slot(slot_name)
renderable_value = send(default_method)
slot = Slot.new(self)

if renderable_value.respond_to?(:render_in)
if renderable_value.class.method_defined?(:render_in)
slot.__vc_component_instance = renderable_value
else
slot.__vc_content = renderable_value
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component/translatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def i18n_scope
private

def html_safe_translation(translation)
if translation.respond_to?(:map)
if translation.class.method_defined?(:map)
translation.map { |element| html_safe_translation(element) }
else
# It's assumed here that objects loaded by the i18n backend will respond to `#html_safe?`.
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/test/rendering_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_render_inline_allocations
MyComponent.ensure_compiled

allocations = (Rails.version.to_f >= 8.0) ?
{"3.5.0" => 104, "3.4.1" => 104, "3.3.7" => 108} :
{"3.5.0" => 102, "3.4.1" => 104, "3.3.7" => 108} :
{"3.3.7" => 107, "3.3.0" => 120, "3.2.7" => 105, "3.1.6" => 118, "3.0.7" => 127}

assert_allocations(**allocations) do
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/test/slotable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_slot_with_respond_to
end
end

assert component.items.first.respond_to?(:classes)
assert_not_nil component.items.first.classes
end

def test_slot_forwards_kwargs_to_component
Expand Down
13 changes: 3 additions & 10 deletions view_component.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ Gem::Specification.new do |spec|
spec.homepage = "https://viewcomponent.org"
spec.license = "MIT"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "https://rubygems.org"
spec.metadata["source_code_uri"] = "https://github.com/viewcomponent/view_component"
spec.metadata["changelog_uri"] = "https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.metadata["allowed_push_host"] = "https://rubygems.org"
spec.metadata["source_code_uri"] = "https://github.com/viewcomponent/view_component"
spec.metadata["changelog_uri"] = "https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md"

spec.files = Dir["LICENSE.txt", "README.md", "app/**/*", "docs/CHANGELOG.md", "lib/**/*"]
spec.require_paths = ["lib"]
Expand Down
Loading