Skip to content

Business intelligence made simple

Dropped support for Rails < 5

Andrew Kane78609f3fbe83
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7fd7258d..7c4f515b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.2.0 [unreleased]
+
+- Dropped support for Rails 4.2
+
## 2.1.0
- Require latest Chartkick to prevent possible XSS - see [#245](https://github.com/ankane/blazer/issues/245)
diff --git a/app/controllers/blazer/base_controller.rb b/app/controllers/blazer/base_controller.rb
index 7790e07d..9d14b84d 100644
--- a/app/controllers/blazer/base_controller.rb
+++ b/app/controllers/blazer/base_controller.rb
@@ -2,13 +2,9 @@ module Blazer
class BaseController < ApplicationController
# skip filters
filters = _process_action_callbacks.map(&:filter) - [:activate_authlogic]
- if Rails::VERSION::MAJOR >= 5
- skip_before_action(*filters, raise: false)
- skip_after_action(*filters, raise: false)
- skip_around_action(*filters, raise: false)
- else
- skip_action_callback(*filters)
- end
+ skip_before_action(*filters, raise: false)
+ skip_after_action(*filters, raise: false)
+ skip_around_action(*filters, raise: false)
protect_from_forgery with: :exception
diff --git a/app/models/blazer/audit.rb b/app/models/blazer/audit.rb
index edb60610..3c31a5cd 100644
--- a/app/models/blazer/audit.rb
+++ b/app/models/blazer/audit.rb
@@ -1,6 +1,6 @@
module Blazer
class Audit < Record
- belongs_to :user, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s)
- belongs_to :query, Blazer::BELONGS_TO_OPTIONAL
+ belongs_to :user, optional: true, class_name: Blazer.user_class.to_s
+ belongs_to :query, optional: true
end
end
diff --git a/app/models/blazer/check.rb b/app/models/blazer/check.rb
index bab53709..194c3797 100644
--- a/app/models/blazer/check.rb
+++ b/app/models/blazer/check.rb
@@ -1,6 +1,6 @@
module Blazer
class Check < Record
- belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
+ belongs_to :creator, optional: true, class_name: Blazer.user_class.to_s if Blazer.user_class
belongs_to :query
validates :query_id, presence: true
diff --git a/app/models/blazer/dashboard.rb b/app/models/blazer/dashboard.rb
index 57b4cac8..941d95ab 100644
--- a/app/models/blazer/dashboard.rb
+++ b/app/models/blazer/dashboard.rb
@@ -1,6 +1,6 @@
module Blazer
class Dashboard < Record
- belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
+ belongs_to :creator, optional: true, class_name: Blazer.user_class.to_s if Blazer.user_class
has_many :dashboard_queries, dependent: :destroy
has_many :queries, through: :dashboard_queries
diff --git a/app/models/blazer/query.rb b/app/models/blazer/query.rb
index 2e1cc168..1a100612 100644
--- a/app/models/blazer/query.rb
+++ b/app/models/blazer/query.rb
@@ -1,6 +1,6 @@
module Blazer
class Query < Record
- belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
+ belongs_to :creator, optional: true, class_name: Blazer.user_class.to_s if Blazer.user_class
has_many :checks, dependent: :destroy
has_many :dashboard_queries, dependent: :destroy
has_many :dashboards, through: :dashboard_queries
diff --git a/blazer.gemspec b/blazer.gemspec
index 9303c763..46eb64be 100644
--- a/blazer.gemspec
+++ b/blazer.gemspec
@@ -1,7 +1,4 @@
-
-lib = File.expand_path("../lib", __FILE__)
-$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require "blazer/version"
+require_relative "lib/blazer/version"
Gem::Specification.new do |spec|
spec.name = "blazer"
@@ -16,10 +13,10 @@ Gem::Specification.new do |spec|
spec.files = Dir["*.{md,txt}", "{app,config,lib}/**/*"]
spec.require_path = "lib"
- spec.required_ruby_version = ">= 2.3"
+ spec.required_ruby_version = ">= 2.4"
- spec.add_dependency "railties", ">= 4.2"
- spec.add_dependency "activerecord", ">= 4.2"
+ spec.add_dependency "railties", ">= 5"
+ spec.add_dependency "activerecord", ">= 5"
spec.add_dependency "chartkick", ">= 3.2"
spec.add_dependency "safely_block", ">= 0.1.1"
diff --git a/lib/blazer.rb b/lib/blazer.rb
index 56fc2aa2..8d6eb001 100644
--- a/lib/blazer.rb
+++ b/lib/blazer.rb
@@ -72,8 +72,6 @@ module Blazer
"system requested abort", # redshift
"maximum statement execution time exceeded" # mysql
]
- BELONGS_TO_OPTIONAL = {}
- BELONGS_TO_OPTIONAL[:optional] = true if Rails::VERSION::MAJOR >= 5
def self.time_zone=(time_zone)
@time_zone = time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone[time_zone.to_s]
diff --git a/lib/blazer/adapters/sql_adapter.rb b/lib/blazer/adapters/sql_adapter.rb
index 94c828c7..563a35b3 100644
--- a/lib/blazer/adapters/sql_adapter.rb
+++ b/lib/blazer/adapters/sql_adapter.rb
@@ -26,9 +26,8 @@ module Blazer
result = select_all("#{statement} /*#{comment}*/")
columns = result.columns
- cast_method = Rails::VERSION::MAJOR < 5 ? :type_cast : :cast_value
result.rows.each do |untyped_row|
- rows << (result.column_types.empty? ? untyped_row : columns.each_with_index.map { |c, i| untyped_row[i] ? result.column_types[c].send(cast_method, untyped_row[i]) : untyped_row[i] })
+ rows << (result.column_types.empty? ? untyped_row : columns.each_with_index.map { |c, i| untyped_row[i] ? result.column_types[c].send(:cast_value, untyped_row[i]) : untyped_row[i] })
end
end
rescue => e
diff --git a/lib/generators/blazer/install_generator.rb b/lib/generators/blazer/install_generator.rb
index f6b53b74..fa7435f2 100644
--- a/lib/generators/blazer/install_generator.rb
+++ b/lib/generators/blazer/install_generator.rb
@@ -15,9 +15,7 @@ module Blazer
end
def migration_version
- if ActiveRecord::VERSION::MAJOR >= 5
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
- end
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end
end
end