class BallonizerProxyGenerator
A class to automate the creation of an rack app that offer multiple BallonizerProxys. The constructor only takes a hash (often parsed from a JSON config file) and create a rack app that can be accessed by app
.
The hash format is as follows:
h has a String path (that start and end with slashes) all the proxy apps will be inside this namespace/‘virtual directory’.
h has an Array with the Hashes of the individual settings of each ballonizer proxy. The ‘proxy_path’, ‘original_domain’, ‘original_paths’ are as the PrettyProxy parameters with the same name. The ‘database_uri’ is equivalent to the database parameter of the Ballonizer constructor. These four are obrigatory. The rest of the options are as the ones described for the settings hash of the Ballonizer constructor. It’s NOT RECOMMENDED to configure the :form_handler_url, :add_required_*, :add_js_for_edition, :*_asset_path_for_link, options, these options are automatically defined. The purpose of this class is mainly to handle this configuration for you, so doesn’t make much sense to define these settings.
Use ‘rake example’ to run the example. You can see the results in localhost:your_server_port/proxys/xkcd/pt-br/ and localhost:your_server_port/proxys/cardboad-crack/pt-br/. The configuration file is in example/settings_example.json
This documentation is also avaliable in: www.omniref.com/ruby/gems/ballonizer_proxy
@author Henrique Becker
Constants
- ASSET_PATH
Public Class Methods
# File lib/ballonizer_proxy.rb, line 120 def initialize(settings) @settings = PrivateUtils.deep_freeze(settings) @ballonizer_proxys = [] @settings['ballonizer_proxys'].each do | bp_config | ballonizer_settings = {} Ballonizer::DEFAULT_SETTINGS.each_key do | key | value = bp_config[key.to_s] if value ballonizer_settings[key] = value end end ballonizer_settings = { form_handler_url: bp_config['proxy_path'] + 'request_handler', add_required_css: true, add_required_js_libs_for_edition: true, add_js_for_edition: true, jquery_no_conflict: true, create_tables_if_none: true, # the paths for assets are made absolute in BallonizerProxy css_asset_path_for_link: ASSET_PATH, js_asset_path_for_link: ASSET_PATH }.merge(ballonizer_settings) @ballonizer_proxys << BallonizerProxy.new( @settings['proxys_namespace'] + bp_config['proxy_path'][1..-1], bp_config['original_domain'], bp_config['original_paths'], bp_config['database_uri'], ballonizer_settings ) end proxys_namespace = @settings['proxys_namespace'] ballonizer_proxys = @ballonizer_proxys @app = Rack::Builder.new do map ASSET_PATH do run Ballonizer.assets_app end ballonizer_proxys.each do | bp | map bp.proxy_path do run bp end map bp.ballonizer.settings[:form_handler_url] do run(lambda do | env | begin bp.ballonizer.process_submit(env) [200, {}, ['your changes have been stored successfully']] rescue Ballonizer::SubmitError => e [200, {}, [e.message]] end end) end end end end
Public Instance Methods
# File lib/ballonizer_proxy.rb, line 177 def app @app end