Skip to content

Commit df8e4f9

Browse files
committed
Rubocop fixes
1 parent c188b82 commit df8e4f9

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

app/concerns/better_together/searchable.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
# app/models/concerns/searchable.rb
24

35
module BetterTogether
46
# Enables ElasticSearch
57
module Searchable
68
extend ActiveSupport::Concern
7-
9+
810
included do
911
include Elasticsearch::Model
1012
include Elasticsearch::Model::Callbacks
@@ -27,4 +29,4 @@ def index_document
2729
__elasticsearch__.index_document
2830
end
2931
end
30-
end
32+
end
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
module BetterTogether
1+
# frozen_string_literal: true
2+
3+
module BetterTogether
4+
# Handles dispatching search queries to elasticsearch and displaying the results
25
class SearchController < ApplicationController
36
def search
47
@query = params[:q]
5-
if @query.present?
6-
@results = BetterTogether::Page.search(@query).records
7-
else
8-
@results = []
9-
end
8+
@results = if @query.present?
9+
BetterTogether::Page.search(@query).records
10+
else
11+
[]
12+
end
1013
end
1114
end
12-
end
15+
end

app/models/better_together/navigation_item.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ def title=(arg)
118118
end
119119

120120
def url
121-
_url = '#'
121+
fallback_url = '#'
122122

123123
if linkable.present?
124124
linkable.url
125125
elsif route_name.present? # If the route_name is present, use the dynamic route
126126
retrieve_route(route_name)
127127
else
128-
read_attribute(:url) or _url
128+
read_attribute(:url) or fallback_url
129129
end
130130
end
131131

app/models/better_together/page.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class Page < ApplicationRecord
1616
has_many :page_blocks, -> { positioned }, dependent: :destroy, class_name: 'BetterTogether::Content::PageBlock'
1717
has_many :blocks, through: :page_blocks
1818
has_many :image_blocks, -> { where(type: 'BetterTogether::Content::Image') }, through: :page_blocks, source: :block
19-
has_many :rich_text_blocks, -> { where(type: 'BetterTogether::Content::RichText') }, through: :page_blocks, source: :block
19+
has_many :rich_text_blocks, lambda {
20+
where(type: 'BetterTogether::Content::RichText')
21+
}, through: :page_blocks, source: :block
2022

2123
accepts_nested_attributes_for :page_blocks, allow_destroy: true
2224

@@ -53,15 +55,13 @@ class Page < ApplicationRecord
5355
scope :by_publication_date, -> { order(published_at: :desc) }
5456

5557
# Customize the data sent to Elasticsearch for indexing
56-
def as_indexed_json(options = {})
57-
self.as_json(
58+
def as_indexed_json(_options = {}) # rubocop:todo Metrics/MethodLength
59+
as_json(
5860
methods: [:title, :content, *self.class.localized_attribute_list],
59-
61+
6062
include: {
6163
rich_text_content: { only: :body },
62-
image_blocks: {
63-
64-
},
64+
image_blocks: {},
6565
rich_text_blocks: {
6666
include: {
6767
rich_text_content: { only: :body }
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
# config/initializers/elasticsearch.rb
24
Elasticsearch::Model.client = Elasticsearch::Client.new(
3-
port: ENV.fetch('ES_PORT') { 9200 },
4-
host: ENV.fetch('ES_HOST') { 'http://es' },
5-
url: ENV.fetch('ELASTICSEARCH_URL') { 'http://elasticsearch:9201' }
5+
port: ENV.fetch('ES_PORT', 9200),
6+
host: ENV.fetch('ES_HOST', 'http://es'),
7+
url: ENV.fetch('ELASTICSEARCH_URL', 'http://elasticsearch:9201')
68
)

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
sign_up: 'sign-up'
3131
},
3232
defaults: { format: :html, locale: I18n.locale }
33-
33+
3434
get 'search', to: 'search#search'
3535
authenticated :user do # rubocop:todo Metrics/BlockLength
3636
resources :communities, only: %i[index show]

0 commit comments

Comments
 (0)