Class: Bowline::Configuration
Overview
ships with defaults that suites most Bowline applications. But it’s possible to overwrite everything. Usually, you’ll create an Configuration file implicitly through the block running on the Initializer, but it’s also possible to create the Configuration instance in advance and pass it in like this:
config = Bowline::Configuration.new
Bowline::Initializer.run(:process, config)
Instance Attribute Summary collapse
-
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base.
-
#active_resource ⇒ Object
A stub for setting options on ActiveResource::Base.
-
#active_support ⇒ Object
A stub for setting options on ActiveSupport.
-
#app_config_file ⇒ Object
Returns the value of attribute app_config_file.
-
#autoload_once_paths ⇒ Object
An array of paths from which Bowline will automatically load from only once.
-
#autoload_paths ⇒ Object
An array of additional paths to prepend to the load path.
-
#binder_paths ⇒ Object
Returns the value of attribute binder_paths.
-
#bowline ⇒ Object
Returns the value of attribute bowline.
-
#cache_classes ⇒ Object
Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request).
-
#copyright ⇒ Object
Returns the value of attribute copyright.
-
#database_configuration_file ⇒ Object
The path to the database configuration file to use.
-
#dependency_loading ⇒ Object
Returns the value of attribute dependency_loading.
-
#description ⇒ Object
Returns the value of attribute description.
-
#eager_load_paths ⇒ Object
An array of paths from which Bowline will eager load on boot if cache classes is enabled.
-
#first_run_glob ⇒ Object
Returns the value of attribute first_run_glob.
-
#frameworks ⇒ Object
Returns the value of attribute frameworks.
-
#helper_glob ⇒ Object
Returns the value of attribute helper_glob.
-
#icon ⇒ Object
Set the application’s icon.
-
#id ⇒ Object
Set the application’s globally unique id.
-
#initializer_glob ⇒ Object
Returns the value of attribute initializer_glob.
-
#log_level ⇒ Object
The log level to use for the default Bowline logger.
-
#log_path ⇒ Object
The path to the log file to use.
-
#logger ⇒ Object
The specific logger to use.
-
#marshal_path ⇒ Object
Returns the value of attribute marshal_path.
-
#name ⇒ Object
Set the application’s name.
-
#plugin_glob ⇒ Object
Returns the value of attribute plugin_glob.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#reload_plugins ⇒ Object
Returns the value of attribute reload_plugins.
-
#root_path ⇒ Object
readonly
The application’s base directory.
-
#time_zone ⇒ Object
Sets the default
time_zone
. -
#url ⇒ Object
Returns the value of attribute url.
-
#version ⇒ Object
Set the application’s version.
-
#whiny_nils ⇒ Object
Set to
true
if you want to be warned (noisily) when you try to invoke any method ofnil
.
Instance Method Summary collapse
-
#after_initialize(&after_initialize_block) ⇒ Object
Adds a block which will be executed after bowline has been fully initialized.
-
#after_initialize_blocks ⇒ Object
Returns the blocks added with Configuration#after_initialize.
-
#database_configuration ⇒ Object
Loads and returns the contents of the #database_configuration_file.
- #helpers ⇒ Object
-
#initialize ⇒ Configuration
constructor
Create a new Configuration instance, initialized with the default values.
-
#reload_plugins? ⇒ Boolean
Returns true if plugin reloading is enabled.
-
#set_root_path! ⇒ Object
Set the root_path to APP_ROOT and canonicalize it.
- #threadsafe! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Create a new Configuration instance, initialized with the default values.
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/bowline/initializer.rb', line 492 def initialize set_root_path! self.frameworks = default_frameworks self.autoload_paths = default_autoload_paths self.autoload_once_paths = default_autoload_once_paths self.dependency_loading = default_dependency_loading self.eager_load_paths = default_eager_load_paths self.log_path = default_log_path self.log_level = default_log_level self.binder_paths = default_binder_paths self.marshal_path = default_marshal_path self.cache_classes = default_cache_classes self.whiny_nils = default_whiny_nils self.database_configuration_file = default_database_configuration_file self.app_config_file = default_app_config_file self.plugin_glob = default_plugin_glob self.helper_glob = default_helper_glob self.initializer_glob = default_initalizer_glob self.first_run_glob = default_first_run_glob self.publisher = default_publisher self.copyright = default_copyright for framework in default_frameworks self.send("#{framework}=", Bowline::OrderedOptions.new) end end |
Instance Attribute Details
#active_record ⇒ Object
A stub for setting options on ActiveRecord::Base.
383 384 385 |
# File 'lib/bowline/initializer.rb', line 383 def active_record @active_record end |
#active_resource ⇒ Object
A stub for setting options on ActiveResource::Base.
386 387 388 |
# File 'lib/bowline/initializer.rb', line 386 def active_resource @active_resource end |
#active_support ⇒ Object
A stub for setting options on ActiveSupport.
389 390 391 |
# File 'lib/bowline/initializer.rb', line 389 def active_support @active_support end |
#app_config_file ⇒ Object
Returns the value of attribute app_config_file.
407 408 409 |
# File 'lib/bowline/initializer.rb', line 407 def app_config_file @app_config_file end |
#autoload_once_paths ⇒ Object
An array of paths from which Bowline will automatically load from only once. All elements of this array must also be in load_paths
.
415 416 417 |
# File 'lib/bowline/initializer.rb', line 415 def autoload_once_paths @autoload_once_paths end |
#autoload_paths ⇒ Object
An array of additional paths to prepend to the load path. By default, all app
, lib
, vendor
and mock paths are included in this list.
411 412 413 |
# File 'lib/bowline/initializer.rb', line 411 def autoload_paths @autoload_paths end |
#binder_paths ⇒ Object
Returns the value of attribute binder_paths.
399 400 401 |
# File 'lib/bowline/initializer.rb', line 399 def binder_paths @binder_paths end |
#bowline ⇒ Object
Returns the value of attribute bowline.
391 392 393 |
# File 'lib/bowline/initializer.rb', line 391 def bowline @bowline end |
#cache_classes ⇒ Object
Whether or not classes should be cached (set to false if you want application classes to be reloaded on each request)
397 398 399 |
# File 'lib/bowline/initializer.rb', line 397 def cache_classes @cache_classes end |
#copyright ⇒ Object
Returns the value of attribute copyright.
489 490 491 |
# File 'lib/bowline/initializer.rb', line 489 def copyright @copyright end |
#database_configuration_file ⇒ Object
The path to the database configuration file to use. (Defaults to config/database.yml
.)
405 406 407 |
# File 'lib/bowline/initializer.rb', line 405 def database_configuration_file @database_configuration_file end |
#dependency_loading ⇒ Object
Returns the value of attribute dependency_loading.
445 446 447 |
# File 'lib/bowline/initializer.rb', line 445 def dependency_loading @dependency_loading end |
#description ⇒ Object
Returns the value of attribute description.
477 478 479 |
# File 'lib/bowline/initializer.rb', line 477 def description @description end |
#eager_load_paths ⇒ Object
An array of paths from which Bowline will eager load on boot if cache classes is enabled. All elements of this array must also be in autoload_paths
.
420 421 422 |
# File 'lib/bowline/initializer.rb', line 420 def eager_load_paths @eager_load_paths end |
#first_run_glob ⇒ Object
Returns the value of attribute first_run_glob.
459 460 461 |
# File 'lib/bowline/initializer.rb', line 459 def first_run_glob @first_run_glob end |
#frameworks ⇒ Object
Returns the value of attribute frameworks.
393 394 395 |
# File 'lib/bowline/initializer.rb', line 393 def frameworks @frameworks end |
#helper_glob ⇒ Object
Returns the value of attribute helper_glob.
458 459 460 |
# File 'lib/bowline/initializer.rb', line 458 def helper_glob @helper_glob end |
#icon ⇒ Object
Set the application’s icon. Point this variable to the icons path.
If this isn’t specified, Bowline’s default one will be used.
Supported icon files are PNGs and JPGs, preferably 512px x 512px.
486 487 488 |
# File 'lib/bowline/initializer.rb', line 486 def icon @icon end |
#id ⇒ Object
Set the application’s globally unique id. This is required. Example:
config.id = "com.maccman.bowline"
470 471 472 |
# File 'lib/bowline/initializer.rb', line 470 def id @id end |
#initializer_glob ⇒ Object
Returns the value of attribute initializer_glob.
460 461 462 |
# File 'lib/bowline/initializer.rb', line 460 def initializer_glob @initializer_glob end |
#log_level ⇒ Object
The log level to use for the default Bowline logger.
423 424 425 |
# File 'lib/bowline/initializer.rb', line 423 def log_level @log_level end |
#log_path ⇒ Object
The path to the log file to use. Defaults to log/#environment.log (e.g. log/development.log or log/production.log).
427 428 429 |
# File 'lib/bowline/initializer.rb', line 427 def log_path @log_path end |
#logger ⇒ Object
The specific logger to use. By default, a logger will be created and initialized using #log_path and #log_level, but a programmer may specifically set the logger to use via this accessor and it will be used directly.
433 434 435 |
# File 'lib/bowline/initializer.rb', line 433 def logger @logger end |
#marshal_path ⇒ Object
Returns the value of attribute marshal_path.
401 402 403 |
# File 'lib/bowline/initializer.rb', line 401 def marshal_path @marshal_path end |
#name ⇒ Object
Set the application’s name. This is required.
464 465 466 |
# File 'lib/bowline/initializer.rb', line 464 def name @name end |
#plugin_glob ⇒ Object
Returns the value of attribute plugin_glob.
457 458 459 |
# File 'lib/bowline/initializer.rb', line 457 def plugin_glob @plugin_glob end |
#publisher ⇒ Object
Returns the value of attribute publisher.
488 489 490 |
# File 'lib/bowline/initializer.rb', line 488 def publisher @publisher end |
#reload_plugins ⇒ Object
Returns the value of attribute reload_plugins.
439 440 441 |
# File 'lib/bowline/initializer.rb', line 439 def reload_plugins @reload_plugins end |
#root_path ⇒ Object (readonly)
The application’s base directory.
380 381 382 |
# File 'lib/bowline/initializer.rb', line 380 def root_path @root_path end |
#time_zone ⇒ Object
Sets the default time_zone
. Setting this will enable time_zone
awareness for Active Record models and set the Active Record default timezone to :utc
.
455 456 457 |
# File 'lib/bowline/initializer.rb', line 455 def time_zone @time_zone end |
#url ⇒ Object
Returns the value of attribute url.
478 479 480 |
# File 'lib/bowline/initializer.rb', line 478 def url @url end |
#version ⇒ Object
Set the application’s version. Example:
config.version = "0.1.2"
475 476 477 |
# File 'lib/bowline/initializer.rb', line 475 def version @version end |
#whiny_nils ⇒ Object
Set to true
if you want to be warned (noisily) when you try to invoke any method of nil
. Set to false
for the standard Ruby behavior.
437 438 439 |
# File 'lib/bowline/initializer.rb', line 437 def whiny_nils @whiny_nils end |
Instance Method Details
#after_initialize(&after_initialize_block) ⇒ Object
Adds a block which will be executed after bowline has been fully initialized. Useful for per-environment configuration which depends on the framework being fully initialized.
555 556 557 |
# File 'lib/bowline/initializer.rb', line 555 def after_initialize(&after_initialize_block) after_initialize_blocks << after_initialize_block if after_initialize_block end |
#after_initialize_blocks ⇒ Object
Returns the blocks added with Configuration#after_initialize
560 561 562 |
# File 'lib/bowline/initializer.rb', line 560 def after_initialize_blocks @after_initialize_blocks ||= [] end |
#database_configuration ⇒ Object
Loads and returns the contents of the #database_configuration_file. The contents of the file are processed via ERB before being sent through YAML::load.
543 544 545 546 |
# File 'lib/bowline/initializer.rb', line 543 def database_configuration require 'erb' YAML::load(ERB.new(IO.read(database_configuration_file)).result) if File.exists?(database_configuration_file) end |
#helpers ⇒ Object
548 549 550 |
# File 'lib/bowline/initializer.rb', line 548 def helpers Dir[helper_glob].map {|f| File.basename(f, '.rb').classify } end |
#reload_plugins? ⇒ Boolean
Returns true if plugin reloading is enabled.
441 442 443 |
# File 'lib/bowline/initializer.rb', line 441 def reload_plugins? !!@reload_plugins end |
#set_root_path! ⇒ Object
Set the root_path to APP_ROOT and canonicalize it.
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/bowline/initializer.rb', line 521 def set_root_path! raise 'APP_ROOT is not set' unless defined?(::APP_ROOT) raise 'APP_ROOT is not a directory' unless File.directory?(::APP_ROOT) @root_path = # Pathname is incompatible with Windows, but Windows doesn't have # real symlinks so File.expand_path is safe. if RUBY_PLATFORM =~ /(:?mswin|mingw)/ File.(::APP_ROOT) # Otherwise use Pathname#realpath which respects symlinks. else Pathname.new(::APP_ROOT).realpath.to_s end Object.const_set(:RELATIVE_APP_ROOT, ::APP_ROOT.dup) unless defined?(::RELATIVE_APP_ROOT) ::APP_ROOT.replace @root_path end |
#threadsafe! ⇒ Object
447 448 449 450 |
# File 'lib/bowline/initializer.rb', line 447 def threadsafe! self.cache_classes = true self.dependency_loading = false end |