Skip to content

Commit

Permalink
fix: initialize empty WeekdaySelectComponent if Rails < 7 (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse authored Mar 17, 2022
1 parent 2a305e9 commit 941cebf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Fix broken gem initialization due to missing ViewComponent::Form constant (#114)
- Initialize empty WeekdaySelectComponent if Rails < 7 to fix Zeitwerk error (#115)

## [0.2.0] - 2022-03-02
### Added
Expand Down
34 changes: 18 additions & 16 deletions app/components/view_component/form/weekday_select_component.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
# frozen_string_literal: true

if Rails::VERSION::MAJOR >= 7
module ViewComponent
module Form
class WeekdaySelectComponent < FieldComponent
attr_reader :html_options
module ViewComponent
module Form
class WeekdaySelectComponent < FieldComponent
attr_reader :html_options

def initialize(form, object_name, method_name, options = {}, html_options = {})
@html_options = html_options
def initialize(form, object_name, method_name, options = {}, html_options = {})
@html_options = html_options

super(form, object_name, method_name, options)
super(form, object_name, method_name, options)

set_html_options!
end
set_html_options!
end

def call
def call # rubocop:disable Metrics/MethodLength
if Rails::VERSION::MAJOR >= 7 # rubocop:disable Style/GuardClause
ActionView::Helpers::Tags::WeekdaySelect.new(
object_name,
method_name,
@view_context,
options,
html_options
).render
else
raise NotImplementedError, "#{self.class} is only available in Rails >= 7"
end
end

protected
protected

def set_html_options!
@html_options[:class] = class_names(html_options[:class], html_class)
@html_options.delete(:class) if @html_options[:class].blank?
end
def set_html_options!
@html_options[:class] = class_names(html_options[:class], html_class)
@html_options.delete(:class) if @html_options[:class].blank?
end
end
end
Expand Down

0 comments on commit 941cebf

Please # to comment.