Skip to content

Commit

Permalink
Add Railtie
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Dec 18, 2017
1 parent bd2f90e commit b7faefe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mls.rb
Expand Up @@ -159,3 +159,5 @@ module MLS::Avatar
end

Dir.glob(File.join(File.dirname(__FILE__), 'mls', '*.rb'), &method(:require))

require 'mls/railtie' if defined?(Rails)
33 changes: 33 additions & 0 deletions lib/mls/railtie.rb
@@ -0,0 +1,33 @@
# See notes from 'active_record/railtie'
require "action_controller/railtie"
require "active_record/railtie"

class MLS::Railtie < Rails::Railtie

config.mls = ActiveSupport::OrderedOptions.new

config.action_dispatch.rescue_responses.merge!(
"Sunstone::Exception::NotFound" => :not_found,
"Sunstone::Exception::Unauthorized" => :conflict,
"Sunstone::Exception::Gone" => :gone
)

initializer 'mls' do |app|

url = app.config.mls.fetch('url') { app.secrets.mls }
user_agent = []
user_agent << app.config.mls.fetch('user_agent') {
app.class.name.split('::')[0..-2].join('::')
}
user_agent << "Rails/#{Rails.version}"


MLS::Model.establish_connection({
adapter: 'sunstone',
url: url,
user_agent: user_agent.compact.join(' ')
})

end

end

0 comments on commit b7faefe

Please sign in to comment.