announcement-test/temp_file/config/application.rb

150 lines
5.5 KiB
Ruby
Raw Normal View History

require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
require "rails/test_unit/railtie"
require "mongoid"
require "mongoid/railtie"
require "bson"
if Mongoid::VERSION.to_i < 5
require "moped"
Moped::BSON = BSON
else
Mongoid::Sessions = Mongoid::Clients
Mongoid::Clients::StorageOptions::ClassMethods.module_eval do
def store_in(options)
options[:client] = options.delete(:session) if options && options[:session]
Mongoid::Clients::Validators::Storage.validate(self, options)
storage_options.merge!(options)
end
end
2021-11-27 05:37:57 +00:00
#monkey the behavier as before(mongoid 4)
module Mongoid
module Contextual
class Mongo
def add_default_sort_options
if !criteria.options.key?(:sort)
criteria.options[:sort] = {:_id => 1}
apply_option(:sort)
end
end
def first
add_default_sort_options
return documents.first if cached? && cache_loaded?
try_cache(:first) do
if raw_doc = view.limit(-1).first
doc = Factory.from_db(klass, raw_doc, criteria.options[:fields])
eager_load([doc]).first
end
end
end
def last
add_default_sort_options
try_cache(:last) do
with_inverse_sorting do
if raw_doc = view.limit(-1).first
doc = Factory.from_db(klass, raw_doc, criteria.options[:fields])
eager_load([doc]).first
end
end
end
end
def documents_for_iteration
add_default_sort_options
return documents if cached? && !documents.empty?
return view unless eager_loadable?
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria.options[:fields]) }
eager_load(docs)
end
end
end
end
BSON::Int64.class_eval do
def bson_int64?
self.to_bson_key.bson_int64?
end
end
end
module Mongoid
module Findable
def and_any_of(conditions)
self.or(conditions)
end
end
end
module Mongoid
class Criteria
def and_any_of(conditions)
if self.selector.count==0
tmp = self.or(conditions)
else
all_selector = self.selector
self.selector = {}
tmp = self.and([all_selector,{"$or"=>conditions}])
end
tmp
end
end
end
module ActionView::Helpers::AssetTagHelper
self.included do
def stylesheet_link_tag(*sources)
options = sources.extract_options!.stringify_keys
super(*sources,{media: :all}.merge(options))
end
end
end
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
dependency_gems = Gem::Specification.find_all.to_a.flat_map{|spec| spec.dependent_specs.map{|s| [s.name,s.version.to_s]}}.uniq.to_h
dependency_gems = dependency_gems.select{|gem,v| v=='0.0.1'}.keys
dependency_gems.each{|gem_name| Bundler.require.push(Bundler::Dependency.new(gem_name,:runtime))}
Bundler.require(:default, Rails.env)
module Orbit
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# tell the I18n library where to find your translations
I18n.load_path += Dir[Rails.root.join('lib', 'locale', '*.{rb,yml}')]
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
I18n.load_path += Gem::Specification.select{|v| v.source.class!=Bundler::Source::Rubygems}.map{|v| Dir[File.expand_path('../config/locales/*.yml',v.loaded_from)]}.flatten
# set default locale to something other than :en
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :en
extra_lang = File.read('config/extra_lang.txt').scan(/.*extra_.*/).select{|v| v.exclude? '#'}[0].to_s.split(/extra_language.*:|,| /).select{|v| !v.empty?}.map{|v| v.to_sym} rescue []
all_locales = [:en, :zh_tw] + extra_lang
I18n.available_locales = config.i18n.available_locales = all_locales
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
fallbacks = {}
all_locales.each do |locale|
fallbacks[locale] = [locale,:en].uniq #all_locales.sort_by{|v| v == locale ? 0 : 1}
end
I18n.fallbacks = fallbacks
config.autoload_paths += %W(#{config.root}/lib)
#reload_gems = %w(impressionist) # names of gems which should autoreload
#config.autoload_paths += Gem.loaded_specs.values.inject([]){ |a,gem| a += gem.load_paths if reload_gems.include? gem.name; a }
#require 'active_support/dependencies'
#ActiveSupport::Dependencies.explicitly_unloadable_constants += reload_gems.map { |gem| gem.classify }
# config.paths["app/views"].unshift("#{Rails.root}/app/templates")
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Asia/Taipei'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# config.mongoid.observers = :orbit_observer
end
end