Skip to content

Commit

Permalink
Fix Rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Oct 10, 2024
1 parent 0966e65 commit 0ba4bf4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
9 changes: 4 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ Style/NumericPredicate:
##########

Layout/LineLength:
Max: 125
Exclude:
- app/helpers/smart_listing/helper.rb
- lib/smart_listing.rb
- smart_listing.gemspec
Max: 150

Layout/EmptyLines:
Enabled: false
Expand Down Expand Up @@ -108,6 +104,9 @@ RSpec/ExampleLength:
RSpec/MultipleExpectations:
Max: 4

RSpec/NestedGroups:
Max: 4

RSpec/MetadataStyle:
EnforcedStyle: hash

Expand Down
8 changes: 6 additions & 2 deletions app/helpers/smart_listing/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def smart_listing_config
end

# Outputs smart list container
# rubocop:disable Style/IfUnlessModifier
# rubocop:disable Layout/LineLength
def smart_listing_for(name, *args, &block)
raise ArgumentError, 'Missing block' unless block

Expand Down Expand Up @@ -71,7 +71,7 @@ def smart_listing_for(name, *args, &block)
end
end
end
# rubocop:enable Style/IfUnlessModifier
# rubocop:enable Layout/LineLength

def smart_listing_render(name = controller_name, *args)
options = args.dup.extract_options!
Expand All @@ -80,6 +80,7 @@ def smart_listing_render(name = controller_name, *args)
end
end

# rubocop:disable Layout/LineLength
def smart_listing_controls_for(name, *args, &block)
smart_listing = @smart_listings.try(:[], name)

Expand All @@ -92,6 +93,7 @@ def smart_listing_controls_for(name, *args, &block)
concat(capture(&block))
end
end
# rubocop:enable Layout/LineLength

# Render item action buttons (ie. edit, destroy and custom ones)
def smart_listing_item_actions(actions = [])
Expand Down Expand Up @@ -183,6 +185,7 @@ def smart_listing_update(*args)
# Possible calls:
# smart_listing_item name, item_action, object = nil, partial = nil, options = {}
# smart_listing_item item_action, object = nil, partial = nil, options = {}
# rubocop:disable Layout/LineLength
def smart_listing_item(*args)
options = args.extract_options!
if %i[create create_continue destroy edit new remove update].include?(args[1])
Expand All @@ -203,5 +206,6 @@ def smart_listing_item(*args)

render(partial: "smart_listing/item/#{item_action}", locals: { name: name, id: id, valid: valid, object_key: object_key, object: object, part: partial, new: new })
end
# rubocop:enable Layout/LineLength
end
end
2 changes: 2 additions & 0 deletions lib/smart_listing/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(name, collection, options = {})
@collection = @options[:array] ? collection.to_a : collection
end

# rubocop:disable Layout/LineLength
def setup(params, cookies)
@params = params
@params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
Expand Down Expand Up @@ -85,6 +86,7 @@ def setup(params, cookies)
@collection = @collection.page(@page).per(@per_page) if @options[:paginate] && @per_page > 0
end
end
# rubocop:enable Layout/LineLength

def partial
@options[:partial]
Expand Down
4 changes: 4 additions & 0 deletions lib/smart_listing/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def pagination_per_page_links(_options = {})
@template.render(partial: 'smart_listing/pagination_per_page_links', locals: default_locals.merge(locals))
end

# rubocop:disable Style/IfUnlessModifier
def pagination_per_page_link(page)
if @smart_listing.per_page.to_i != page
url = @template.url_for(@smart_listing.params.merge(@smart_listing.all_params(per_page: page, page: 1)))
Expand All @@ -60,6 +61,7 @@ def pagination_per_page_link(page)

@template.render(partial: 'smart_listing/pagination_per_page_link', locals: default_locals.merge(locals))
end
# rubocop:enable Style/IfUnlessModifier

def sortable(title, attribute, options = {})
dirs = options[:sort_dirs] || @smart_listing.sort_dirs || [nil, 'asc', 'desc']
Expand Down Expand Up @@ -108,6 +110,7 @@ def render(options = {}, locals = {}, &block)
end

# Add new item button & placeholder to list
# rubocop:disable Layout/LineLength
def item_new(options = {}, &block)
no_records_classes = [@template.smart_listing_config.classes(:no_records)]
no_records_classes << @template.smart_listing_config.classes(:hidden) unless empty?
Expand Down Expand Up @@ -139,6 +142,7 @@ def item_new(options = {}, &block)

@template.render(partial: 'smart_listing/item_new', locals: default_locals.merge(locals))
end
# rubocop:enable Layout/LineLength

def count
@smart_listing.count
Expand Down

0 comments on commit 0ba4bf4

Please sign in to comment.