lib/ab_admin/utils.rb in ab_admin-0.6.1 vs lib/ab_admin/utils.rb in ab_admin-0.7.0
- old
+ new
@@ -3,10 +3,17 @@
autoload :CSVBuilder, 'ab_admin/utils/csv_builder'
autoload :EvalHelpers, 'ab_admin/utils/eval_helpers'
autoload :Logger, 'ab_admin/utils/logger'
autoload :Mysql, 'ab_admin/utils/mysql'
+ def all_models
+ Kernel.suppress_warnings do
+ Dir.glob(Rails.root.to_s + '/app/models/**/*.rb').reject { |path| path =~ /concerns|shared/ }.each { |file| require file }
+ end
+ ActiveRecord::Base.direct_descendants
+ end
+
def load_files!(base_path = 'lib/utils')
Dir[Rails.root.join("#{base_path}/**/*.rb")].each do |path|
require_dependency path
end
end
@@ -64,14 +71,15 @@
def url_helpers
Rails.application.routes.url_helpers
end
- def full_url(path)
+ def full_url(path, protocol='http://')
return path if path =~ %r{^(http|//)}
- host = AbAdmin.base_url || Rails.application.config.action_mailer.default_url_options[:host] || 'www.example.com'
- "http://#{host}#{path}"
+ duo = Rails.application.config.action_mailer.default_url_options
+ host = AbAdmin.base_url || [duo[:host], duo[:port]].compact.join(':') || 'www.example.com'
+ "#{protocol}#{host}#{path}"
end
def js_date_data
{
formats: I18n.t('date.formats'),
@@ -140,9 +148,9 @@
def test_env?
Rails.env.test? || Rails.env.cucumber?
end
def friendly_token(n=10)
- SecureRandom.base64(n * 2).tr('+/=', 'xyz').first(n)
+ SecureRandom.base64(n * 2).tr('+/=', 'xyz').first(n).downcase
end
end
end