Skip to content

Commit

Permalink
Use Ruby function shorthand and apply standard linting (#376)
Browse files Browse the repository at this point in the history
**This PR:**
- Implements Ruby shorthand for method calls (e.g., `new(method:)
instead of new(method: method)`
- Applies linting via [Standard
Ruby](https://github.com/standardrb/standard)
  • Loading branch information
louis-antonopoulos authored Nov 1, 2024
1 parent c419322 commit fb874aa
Show file tree
Hide file tree
Showing 62 changed files with 282 additions and 269 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You can create static filters that always run the same query:
```ruby
input = Yuriita::Inputs::Expression.new("is", "published")

Yuriita::ExpressionFilter.new(input: input) do |relation|
Yuriita::ExpressionFilter.new(input:) do |relation|
relation.where(published: true)
end
```
Expand Down
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require File.expand_path('../spec/example_app/config/application', __FILE__)
require File.expand_path("../spec/example_app/config/application", __FILE__)

Bundler::GemHelper.install_tasks


Rails.application.load_tasks

task(:default).clear
Expand All @@ -15,4 +14,4 @@ if defined? RSpec
end
end

task :default => :spec
task default: :spec
2 changes: 1 addition & 1 deletion lib/yuriita/assembler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(configuration)

def build(query)
configuration.map do |definition|
definition.apply(query: query)
definition.apply(query:)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/yuriita/clauses/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(filters:, combination:)

def apply(relation)
relations = filters.map { |filter| filter.apply(relation) }
combination.new(base_relation: relation, relations: relations).combine
combination.new(base_relation: relation, relations:).combine
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/yuriita/clauses/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(filters:, keywords:, combination:)

def apply(relation)
relations = filters.map { |filter| filter.apply(relation, keywords) }
combination.new(base_relation: relation, relations: relations).combine
combination.new(base_relation: relation, relations:).combine
end

private
Expand Down
13 changes: 6 additions & 7 deletions lib/yuriita/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ def dispatch(name, relation)

private

def process(action, *args)
def process(action, *)
action = action.to_s

unless method_name = find_method_name(action)
unless (method_name = find_method_name(action))
raise ActionNotFound.new("The action '#{action}' could not be found for #{self.class.name}", self, action)
end

process_action(method_name, *args)
process_action(method_name, *)
end

def process_action(method_name, *args)
send_action(method_name, *args)
def process_action(method_name, *)
send_action(method_name, *)
end
alias send_action send

alias_method :send_action, :send

def find_method_name(action)
if action_method?(action)
Expand Down
2 changes: 1 addition & 1 deletion lib/yuriita/definitions/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def apply(query:)
input = select_input(query)

if input.present?
Clauses::Dynamic.new(filter: filter, input: input)
Clauses::Dynamic.new(filter:, input:)
else
Clauses::Identity.new
end
Expand Down
8 changes: 4 additions & 4 deletions lib/yuriita/definitions/exclusive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(options:, default:)
def apply(query:)
filter = selected_filter(query)

Clauses::Filter.new(filters: [filter], combination: combination)
Clauses::Filter.new(filters: [filter], combination:)
end

private
Expand All @@ -22,9 +22,9 @@ def combination

def selected_filter(query)
Selects::Exclusive.new(
options: options,
default: default,
query: query,
options:,
default:,
query:
).filter
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/yuriita/definitions/multiple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def apply(query:)
filters = selected_filters(query)

if filters.present?
Clauses::Filter.new(filters: filters, combination: combination)
Clauses::Filter.new(filters:, combination:)
else
Clauses::Identity.new
end
Expand All @@ -21,7 +21,7 @@ def apply(query:)
private

def selected_filters(query)
Selects::Multiple.new(options: options, query: query).filters
Selects::Multiple.new(options:, query:).filters
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/yuriita/definitions/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def apply(query:)

if keywords.present?
Clauses::Search.new(
filters: filters,
keywords: keywords,
combination: combination,
filters:,
keywords:,
combination:
)
else
Clauses::Identity.new
Expand All @@ -26,7 +26,7 @@ def apply(query:)
private

def selected_filters(query)
Selects::AllOrExplicit.new(options: options, query: query).filters
Selects::AllOrExplicit.new(options:, query:).filters
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/yuriita/definitions/single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def apply(query:)
filter = selected_filter(query)

if filter.present?
Clauses::Filter.new(filters: [filter], combination: combination)
Clauses::Filter.new(filters: [filter], combination:)
else
Clauses::Identity.new
end
Expand All @@ -24,7 +24,7 @@ def combination
end

def selected_filter(query)
Selects::Single.new(options: options, query: query).filter
Selects::Single.new(options:, query:).filter
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/yuriita/errors/collection/action_not_found.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def initialize(message = nil, collection = nil, action = nil)
@action = action
super(message)
end

end
end
end
1 change: 0 additions & 1 deletion lib/yuriita/or_combination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ def combined_relations
end
end
end

6 changes: 3 additions & 3 deletions lib/yuriita/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def ==(other)
end

def keywords
inputs.select{ |input| input.is_a?(Yuriita::Inputs::Keyword) }
inputs.select { |input| input.is_a?(Yuriita::Inputs::Keyword) }
end

def each(&block)
Expand All @@ -26,7 +26,7 @@ def add_input(input)
inputs << input
self
end
alias << add_input
alias_method :<<, :add_input

def delete(input)
inputs.delete(input)
Expand All @@ -42,7 +42,7 @@ def delete_if
def size
inputs.size
end
alias length size
alias_method :length, :size

def initialize_dup(original)
super
Expand Down
2 changes: 1 addition & 1 deletion lib/yuriita/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def append_route(collection, matcher, to:)
end

def route(input, relation)
if route = match_for(input)
if (route = match_for(input))
collection = route.collection
collection.dispatch(route.action, input, relation)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/yuriita/search_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def apply(relation, keywords)

combination.new(
base_relation: relation,
relations: relations,
relations:
).combine
end

Expand Down
2 changes: 1 addition & 1 deletion spec/example_app/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'
require_relative "config/application"

Rails.application.load_tasks
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def parse_document(path)
end

def render_not_found
raise ActionController::RoutingError, 'Not Found'
raise ActionController::RoutingError, "Not Found"
end
end
2 changes: 1 addition & 1 deletion spec/example_app/app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class MoviesController < ApplicationController
def index
table = build_table
render locals: { table: table }
render locals: {table:}
end

private
Expand Down
2 changes: 1 addition & 1 deletion spec/example_app/app/models/genre_sync.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class GenreSync
def self.run(client:)
new(client: client).run
new(client:).run
end

def initialize(client:)
Expand Down
Loading

0 comments on commit fb874aa

Please sign in to comment.