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

Add frozen string literal to production code #217

Merged
merged 2 commits into from
Sep 16, 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
23 changes: 5 additions & 18 deletions .rubocop_todo.yml

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

2 changes: 2 additions & 0 deletions lib/active_record/connection_adapters/chronomodel_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'chrono_model'

module ActiveRecord
Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/tasks/chronomodel_database_tasks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActiveRecord
module Tasks
class ChronomodelDatabaseTasks < PostgreSQLDatabaseTasks
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_record'

require 'chrono_model/conversions'
Expand Down
4 changes: 3 additions & 1 deletion lib/chrono_model/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_record/connection_adapters/postgresql_adapter'

require 'chrono_model/adapter/migrations'
Expand Down Expand Up @@ -84,7 +86,7 @@ def column_definitions; end
define_method(:column_definitions) do |table_name|
return super(table_name) unless is_chrono?(table_name)

on_schema(TEMPORAL_SCHEMA + ',' + self.schema_search_path, recurse: :ignore) { super(table_name) }
on_schema("#{TEMPORAL_SCHEMA},#{self.schema_search_path}", recurse: :ignore) { super(table_name) }
end

# Evaluates the given block in the temporal schema.
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/ddl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'active_support/core_ext/string/strip'
require 'multi_json'

Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/indexes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
module Indexes
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/migrations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
module Migrations
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/migrations_modules/legacy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter
module MigrationsModules
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/migrations_modules/stable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter
module MigrationsModules
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/tsrange.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
module TSRange
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/adapter/upgrade.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
module Upgrade
Expand Down
4 changes: 3 additions & 1 deletion lib/chrono_model/conversions.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module ChronoModel
module Conversions
extend self

ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/
ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/.freeze

def string_to_utc_time(string)
return string if string.is_a?(Time)
Expand Down
4 changes: 3 additions & 1 deletion lib/chrono_model/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Json
extend self
Expand All @@ -19,7 +21,7 @@ def drop
private

def sql(file)
File.dirname(__FILE__) + '/../../sql/' + file
"#{File.dirname(__FILE__)}/../../sql/#{file}"
end

def adapter
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'chrono_model/patches/as_of_time_holder'
require 'chrono_model/patches/as_of_time_relation'

Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/as_of_time_holder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
# Added to classes that need to carry the As-Of date around
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/as_of_time_relation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
# This class is a dummy relation whose scope is only to pass around the
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/association.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
# Patches ActiveRecord::Associations::Association to add support for
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/batches.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
module Batches
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/join_node.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
# This class supports the AR 5.0 code that expects to receive an
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/preloader.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
# Patches ActiveRecord::Associations::Preloader to add support for
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/patches/relation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Patches
module Relation
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/time_gate.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
# Provides the TimeMachine API to non-temporal models that associate
# temporal ones.
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/time_machine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'chrono_model/time_machine/time_query'
require 'chrono_model/time_machine/timeline'
require 'chrono_model/time_machine/history_model'
Expand Down
4 changes: 3 additions & 1 deletion lib/chrono_model/time_machine/history_model.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module TimeMachine
module HistoryModel
Expand Down Expand Up @@ -126,7 +128,7 @@ def descends_from_active_record?
# current class or a descendant (or self).
#
def find_sti_class(type_name)
super(type_name + "::History")
super("#{type_name}::History")
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/time_machine/time_query.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module TimeMachine
#
Expand Down
6 changes: 4 additions & 2 deletions lib/chrono_model/time_machine/timeline.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module TimeMachine
module Timeline
Expand Down Expand Up @@ -35,12 +37,12 @@ def timeline(record = nil, options = {})
end

relation = relation
.order('ts ' << (options[:reverse] ? 'DESC' : 'ASC'))
.order("ts #{options[:reverse] ? 'DESC' : 'ASC'}")

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

sql = "SELECT ts FROM ( #{relation.to_sql} ) AS foo WHERE ts IS NOT NULL"
sql = "SELECT ts FROM ( #{relation.to_sql} ) AS foo WHERE ts IS NOT NULL".dup

if options.key?(:before)
sql << " AND ts < '#{Conversions.time_to_utc_string(options[:before])}'"
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/utilities.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
module Utilities
# Amends the given history item setting a different period.
Expand Down
2 changes: 2 additions & 0 deletions lib/chrono_model/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ChronoModel
VERSION = "1.2.2"
end