Prepare to support ruby 3.3.

This commit is contained in:
邱博亞 2024-02-24 21:12:32 +08:00
parent 5a47481072
commit fa83427442
3 changed files with 54 additions and 55 deletions

View File

@ -136,7 +136,7 @@ class FeedsController < ApplicationController
end
elsif params[:type] == 'update_all'
feed_data = params[:data]
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
feed_data.force_encoding("utf-8")
file.write(feed_data)
@ -151,7 +151,7 @@ class FeedsController < ApplicationController
end
if need_write
feed_data = feed_data.to_json
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
File.open(File.join(feed_directory.to_s,feed.feed_uid + ".json"),"w") do |file|
feed_data.force_encoding("utf-8")
file.write(feed_data)

View File

@ -95,7 +95,7 @@ class SiteFeed
end
main_directory = File.join("#{Rails.root}","public","site_feeds")
feed_directory = File.join(main_directory.to_s, self.id.to_s)
if !force_refresh && File.exists?(feed_directory)
if !force_refresh && File.exist?(feed_directory)
anns = JSON.parse(File.read(File.join(feed_directory.to_s, self.feed_uid + ".json")))[self.channel_key.pluralize] rescue []
else
uri = URI(self.feed_url)
@ -143,7 +143,7 @@ class SiteFeed
end
res = JSON.dump({"announcements" => res_to_json})
end
FileUtils.mkdir_p(feed_directory) if !File.exists?(feed_directory)
FileUtils.mkdir_p(feed_directory) if !File.exist?(feed_directory)
File.open(File.join(feed_directory.to_s,self.feed_uid + ".json"),"w") do |file|
res.force_encoding("utf-8")
file.write(res)

View File

@ -1,8 +1,10 @@
module Feeds
class Engine < ::Rails::Engine
initializer "feeds" do
Rails.application.config.to_prepare do
gem_root = Feeds::Engine.root
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
require File.expand_path('../../../app/models/site_feed_setting', __FILE__)
require File.join(gem_root, 'app/models/site_feed_setting')
if defined?(SiteFeedSetting)
if SiteFeedSetting.count==0
SiteFeedSetting.create
@ -51,12 +53,9 @@ module Feeds
end
end
spec = Gem::Specification.find_by_name("feeds") rescue nil
if !spec.nil?
gem_root = spec.gem_dir
gem_tmp = gem_root + "/tmp/"
f = File.join(gem_tmp + "install_bash")
if File.exists?(f)
gem_tmp = File.join(gem_root, 'tmp')
f = File.join(gem_tmp, "install_bash")
if File.exist?(f)
File.delete(f)
%x(cp "#{gem_root}/config/schedule.rb" config/schedule.rb)
%x(whenever --update-crontab feeds --set environment="#{ENV["RAILS_ENV"]}")