Kemal currently allows setting configuration options via:
Kemal.config.env = "development"
Kemal.config.port = "3456"
I want to do something like with a block:
configuration do |config|
config.env = "development"
config.port = "3456"
...
end
Is this even possible?
Thanks for any insights.
I believe, you could utilize Object#tap method like this:
Kemal.config.tap do |config|
config.env = "development"
config.port = "3456"
...
end
Related
In my config/environment/development.rb, i have
config.ip: 'http://localhost:3000'
In my config/environment/production.rb, i have
config.ip = 'http://52.74.70.227'
I want to use something like config.url = 'http://example.com'
So when someone recives an activation email link from me the link shows http://example.com/abc intead of http://52.74.70.227/abc
in config/environment/development.rb define
config.action_mailer.default_url_options = {host: "localhost:3000"}
in config/environment/production.rb define
config.action_mailer.default_url_options = {host: "example.com"}
for more info check here http://api.rubyonrails.org/classes/ActionMailer/Base.html
I am using Devise+Omniauth , and I defined my own doorkeeper strategy to add a language option
In config/initializers/devise.rb , I set up :
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale}
which initially set lang to :en ( default locale )
this works fine and send the lang options to the remote server for Doorkeeperprocessing
now, how can I change this parameter in my client calling controller ?
I tried to use :
def index
I18n.locale = :fr
Rails.application.config.middleware.use OmniAuth::Builder do
provider :doorkeeper, :setup => lambda{|env| env['omniauth.strategy'].options[:authorize_params][:lang] = env['rack.session'][I18n.locale] }
end
but I got an error :
RuntimeError (can't modify frozen Array):
app/controllers/home_controller.rb:7:in `index'
Is there any better way to do it ? thanks for help
I modified the config/initializers/devise.rb, adding :setup => true
require 'omniauth/strategies/doorkeeper'
config.omniauth :doorkeeper, Rails.application.secrets.doorkeeper_app_id, Rails.application.secrets.doorkeeper_app_secret,
:client_options => {
:site => Rails.application.secrets.doorkeeper_url
},
:authorize_params =>{:lang => I18n.locale},
:setup => true
and I modified my doorkeeper strategy, to include the setup_phase, in which I set the lang option to the current locale.
def setup_phase
request.env['omniauth.strategy'].options[:authorize_params][:lang] = request.params["locale"]
end
How to change code in hooks to reset (iOS) app at specific scenario ?
means only to those scenario where tags mention as #reset
https://github.com/cucumber/cucumber/wiki/Hooks#tagged-hooks
UPDATED for Calabash 0.17 and run-loop 2.0.2
This project contains an example of how to use Cucumber tags and Before hooks to re-install apps and clear application data on simulators and devices.
https://github.com/calabash/ios-smoke-test-app/
In particular, see these two files:
ideviceinstaller wrapper
support/01_launch.rb
I won't reproduce the entire 01_launch.rb example here, but here are the hooks:
Before("#no_relaunch") do
#no_relaunch = true
end
Before('#reset_app_btw_scenarios') do
if xamarin_test_cloud? || LaunchControl.target_is_simulator?
ENV['RESET_BETWEEN_SCENARIOS'] = '1'
else
LaunchControl.install_on_physical_device
end
end
Before('#reset_device_settings') do
if xamarin_test_cloud?
ENV['RESET_BETWEEN_SCENARIOS'] = '1'
elsif LaunchControl.target_is_simulator?
target = LaunchControl.target
instruments = RunLoop::Instruments.new
xcode = instruments.xcode
device = instruments.simulators.find do |sim|
sim.udid == target || sim.instruments_identifier(xcode) == target
end
RunLoop::CoreSimulator.erase(device)
else
LaunchControl.install_on_physical_device
end
end
Before do |scenario|
launcher = LaunchControl.launcher
options = {
#:uia_strategy => :host
#:uia_strategy => :shared_element
:uia_strategy => :preferences
}
relaunch = true
if #no_relaunch
begin
launcher.ping_app
attach_options = options.dup
attach_options[:timeout] = 1
launcher.attach(attach_options)
relaunch = launcher.device == nil
rescue => e
RunLoop.log_info2("Tag says: don't relaunch, but cannot attach to the app.")
RunLoop.log_info2("#{e.class}: #{e.message}")
RunLoop.log_info2("The app probably needs to be launched!")
end
end
if relaunch
launcher.relaunch(options)
launcher.calabash_notify(self)
end
ENV['RESET_BETWEEN_SCENARIOS'] = '0'
# Re-installing the app on a device does not clear the Keychain settings,
# so we must clear them manually.
if scenario.source_tag_names.include?('#reset_device_settings')
if xamarin_test_cloud? || LaunchControl.target_is_physical_device?
keychain_clear
end
end
end
The key is recognize the difference between testing on simulators and devices and testing on the Test Cloud and locally.
You can reset the application settings and content before every Scenario using the RESET_BETWEEN_SCENARIOS env variable.
$ RESET_BETWEEN_SCENARIOS=1 cucumber
You can also implement a backdoor method to reset your app to a good known state. This example is a bit wonky and out of date, but I have used it to great effect in the past - it really speeds up tests - briar-ios-example You can do all kinds of things with backdoors: log users in/out, reset databases, wipe user preferences, add/remove files from the sandbox.
I want to define the following:
config.generators.stylesheets = false
config.generators.javascripts = false
config.generators.helper = false
But despite reading Ror's guide on the subject, I don't get where exactly the methods should go.
I think it belongs in config/application.rb:
module MyApp
class Application < Rails::Application
# Lots of stuff
# Generator configuration
config.generators do |g|
g.orm :active_record
g.template_engine :erb
g.test_framework :test_unit, fixture: false
g.stylesheets false
g.helper false
end
end
end
In Bootstrap.php I have some custom routes using Zend_Controller_Router_Route_Regex.
Everything works fine except when user type in address bar a wrong link.
Ex :
http://mysite/en/1-some-article.html => This is a valid link that matches a ROUTE in Bootstrap.
But when user make a typo mistake like:
http://mysite/en/1-some-article.**html'** or http://mysite/en/1-some-article.**hhtml** , they are not match any ROUTE in Bootstrap, then Zend Framework throws an exception like : No route matched the request
Is there anyway to handle it, like redirecting to a custom page for "No matched routes"?
Any help will be appreciated. Thanks for advance!
Configuration (from comment below)
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.date.timezone = "Europe/London"
;includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
autoloaderNamespaces.Fxml = "Mycms_"
autoloaderNamespaces.Fxml = "Fxml_"
To make use of the ErrorController, you need to set the front controller throwExceptions attribute to false. Put this in your [production] configuration section
resources.frontController.params.throwExceptions = 0
See http://framework.zend.com/manual/1.12/en/zend.controller.exceptions.html and http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour.
I mentioned this in the comments above but you seem to have missed it (you have displayExceptions set to false but not throwExceptions).