Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniformity in percent literals #225

Merged
merged 2 commits into from
Sep 17, 2023
Merged
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
19 changes: 0 additions & 19 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion benchmarks/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

ITERATIONS = 5_000

Foo.create! name: 'Ciao'
Foo.create! name: 'My Foo'
Bar.create! name: 'My Bar'

first_foo = Foo.first

Expand Down Expand Up @@ -58,4 +59,16 @@
x.report('#as_of') do
ITERATIONS.times { first_foo.as_of(Time.now) }
end

x.report('TimeGate .merge') do
ITERATIONS.times { Bar.merge(Bar.all) }
end

x.report('TimeGate .first') do
ITERATIONS.times { Bar.first }
end

x.report('TimeGate .last') do
ITERATIONS.times { Bar.last }
end
end
9 changes: 9 additions & 0 deletions benchmarks/benchmark_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
t.string :name
t.timestamps
end

create_table :bars, force: true do |t|
t.string :name
t.timestamps
end
end

class Foo < ActiveRecord::Base
include ChronoModel::TimeMachine
end

class Bar < ActiveRecord::Base
include ChronoModel::TimeGate
end

def run_benchmark_sample(iterations: 100)
# Create
iterations.times { |i| Foo.create! name: "Foo #{i}" }
Expand Down
6 changes: 3 additions & 3 deletions lib/chrono_model/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def chrono_setup!
#
def primary_key(table_name); end

[:primary_key, :indexes, :default_sequence_name].each do |method|
%i[primary_key indexes default_sequence_name].each do |method|
define_method(method) do |*args|
table_name = args.first
return super(*args) unless is_chrono?(table_name)
Expand Down Expand Up @@ -161,11 +161,11 @@ def chrono_metadata_for(view_name)
def chrono_metadata_set(view_name, metadata)
comment = MultiJson.dump(metadata)

execute %[ COMMENT ON VIEW #{view_name} IS #{quote(comment)} ]
execute %( COMMENT ON VIEW #{view_name} IS #{quote(comment)} )
end

def valid_table_definition_options
super + [:temporal, :journal, :no_journal, :full_journal]
super + %i[temporal journal no_journal full_journal]
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/adapter/ddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def chrono_create_DELETE_trigger(table, pk, current, history)
end

def chrono_drop_trigger_functions_for(table_name)
%w(insert update delete).each do |func|
%w[insert update delete].each do |func|
execute "DROP FUNCTION IF EXISTS chronomodel_#{table_name}_#{func}()"
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chrono_model/adapter/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def chrono_create_history_indexes_for(table, p_pkey)
#
def chrono_rename_history_indexes(name, new_name)
on_history_schema do
standard_index_names = %w(
standard_index_names = %w[
inherit_pkey instance_history pkey
recorded_at timeline_consistency
)
]

old_names = temporal_index_names(name, :validity) +
standard_index_names.map { |i| "#{name}_#{i}" }
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/time_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def as_of(time)

def attribute_names_for_history_changes
@attribute_names_for_history_changes ||= attribute_names -
%w(id hid validity recorded_at)
%w[id hid validity recorded_at]
end

def has_timeline(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/time_machine/history_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def at(time)
# Returns the history sorted by recorded_at
#
def sorted
all.order(Arel.sql(%[ #{quoted_table_name}."recorded_at" ASC, #{quoted_table_name}."hid" ASC ]))
all.order(Arel.sql(%( #{quoted_table_name}."recorded_at" ASC, #{quoted_table_name}."hid" ASC )))
end

# Fetches the given +object+ history, sorted by history record time
Expand Down
2 changes: 1 addition & 1 deletion lib/chrono_model/time_machine/time_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def build_time_query(time, range, op = '&&')
if time.is_a?(Array)
Arel.sql %[ #{range.type}(#{time.first}, #{time.last}) #{op} #{table_name}.#{range.name} ]
else
Arel.sql %[ #{time} <@ #{table_name}.#{range.name} ]
Arel.sql %( #{time} <@ #{table_name}.#{range.name} )
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/chrono_model/time_machine/timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def timeline(record = nil, options = {})

relation = relation.order("ts #{relation_order}")

relation = relation.from(%["public".#{quoted_table_name}]) unless chrono?
relation = relation.from("public.#{quoted_table_name}") unless chrono?
relation = relation.where(id: rid) if rid

sql = "SELECT ts FROM ( #{relation.to_sql} ) AS foo WHERE ts IS NOT NULL".dup
Expand Down Expand Up @@ -110,7 +110,7 @@ def quoted_history_fields
@quoted_history_fields ||= begin
validity = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name('validity')}"

%w(lower upper).map! { |func| "#{func}(#{validity})" }
%w[lower upper].map! { |func| "#{func}(#{validity})" }
end
end
end
Expand Down