2017-04-18 13:54:58 +00:00
|
|
|
require 'uri'
|
|
|
|
|
2013-12-09 18:03:22 +00:00
|
|
|
module Asciinema
|
|
|
|
class Configuration
|
2014-03-21 15:43:32 +00:00
|
|
|
include Virtus.model
|
|
|
|
|
2017-04-18 13:54:58 +00:00
|
|
|
attribute :base_url, String, default: 'http://localhost:3000'
|
2014-08-08 21:11:18 +00:00
|
|
|
attribute :bugsnag_api_key, String
|
2014-03-21 15:43:32 +00:00
|
|
|
attribute :aws_access_key_id, String
|
|
|
|
attribute :aws_secret_access_key, String
|
2017-04-18 12:28:58 +00:00
|
|
|
attribute :s3_bucket, String
|
|
|
|
attribute :s3_region, String
|
2014-03-21 15:43:32 +00:00
|
|
|
attribute :carrierwave_storage_dir_prefix, String, default: 'uploads/'
|
|
|
|
attribute :google_analytics_id, String
|
|
|
|
attribute :home_asciicast_id, Integer
|
2017-04-18 11:55:11 +00:00
|
|
|
attribute :secret_key_base, String
|
2014-07-05 12:59:42 +00:00
|
|
|
attribute :admin_ids, Array[Integer]
|
2014-10-06 19:45:58 +00:00
|
|
|
attribute :smtp_settings, Hash
|
2017-04-18 14:33:07 +00:00
|
|
|
attribute :smtp_from_address, String
|
2014-03-21 15:43:32 +00:00
|
|
|
|
2014-01-17 13:52:37 +00:00
|
|
|
def home_asciicast
|
2015-06-22 18:38:32 +00:00
|
|
|
if home_asciicast_id
|
2014-03-21 15:43:32 +00:00
|
|
|
Asciicast.find(home_asciicast_id)
|
2014-01-17 13:52:37 +00:00
|
|
|
else
|
2017-04-15 16:15:52 +00:00
|
|
|
Asciicast.non_private.order(:id).first
|
2014-01-17 13:52:37 +00:00
|
|
|
end
|
2013-12-09 18:03:22 +00:00
|
|
|
end
|
|
|
|
|
2017-04-18 13:54:58 +00:00
|
|
|
def scheme
|
|
|
|
URI.parse(base_url).scheme
|
|
|
|
end
|
|
|
|
|
2017-04-18 14:33:07 +00:00
|
|
|
def hostname
|
|
|
|
URI.parse(base_url).hostname
|
|
|
|
end
|
|
|
|
|
2017-04-18 13:54:58 +00:00
|
|
|
def hostname_with_port
|
|
|
|
uri = URI.parse(base_url)
|
|
|
|
hwp = uri.hostname
|
|
|
|
|
|
|
|
if uri.port != uri.default_port
|
|
|
|
hwp = "#{hwp}:#{uri.port}"
|
|
|
|
end
|
|
|
|
|
|
|
|
hwp
|
|
|
|
end
|
|
|
|
|
2014-01-29 15:00:50 +00:00
|
|
|
def ssl?
|
|
|
|
scheme == 'https'
|
|
|
|
end
|
|
|
|
|
2017-04-18 14:33:07 +00:00
|
|
|
def smtp_from_address
|
|
|
|
super || "asciinema <hello@#{hostname}>"
|
|
|
|
end
|
2013-12-09 18:03:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-21 15:43:32 +00:00
|
|
|
cfg_file = File.expand_path(File.dirname(__FILE__) + '/asciinema.yml')
|
|
|
|
cfg = YAML.load_file(cfg_file) || {} rescue {}
|
|
|
|
env = Hash[ENV.to_h.map { |k, v| [k.downcase, v] }]
|
|
|
|
cfg.merge!(env)
|
|
|
|
|
2013-12-09 18:03:22 +00:00
|
|
|
::CFG = Asciinema::Configuration.new(cfg)
|