discourse/app/models/embedding.rb
Sam Saffron 9be70a22cd DEV: introduce new API to look up dynamic site setting
This removes all uses of both `send` and `public_send` from consumers of
SiteSetting and instead introduces a `get` helper for dynamic lookup

This leads to much cleaner and safer code long term as we are always explicit
to test that a site setting is really there before sending an arbitrary
string to the class

It also removes a couple of risky stubs from the auth provider test
2019-05-07 11:00:30 +10:00

45 lines
899 B
Ruby

require 'has_errors'
class Embedding < OpenStruct
include HasErrors
def self.settings
%i(embed_by_username
embed_post_limit
embed_title_scrubber
embed_truncate
embed_whitelist_selector
embed_blacklist_selector
embed_classname_whitelist
feed_polling_enabled
feed_polling_url
feed_polling_frequency_mins
embed_username_key_from_feed)
end
def base_url
Discourse.base_url
end
def save
Embedding.settings.each do |s|
SiteSetting.set(s, public_send(s))
end
true
rescue Discourse::InvalidParameters => p
errors.add :base, p.to_s
false
end
def embeddable_hosts
EmbeddableHost.all.order(:host)
end
def self.find
embedding_args = { id: 'default' }
Embedding.settings.each { |s| embedding_args[s] = SiteSetting.send(s) }
Embedding.new(embedding_args)
end
end