Class: Bowline::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bowline/initializer.rb

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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_recordObject

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_resourceObject

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_supportObject

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_fileObject

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_pathsObject

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_pathsObject

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_pathsObject

Returns the value of attribute binder_paths.



399
400
401
# File 'lib/bowline/initializer.rb', line 399

def binder_paths
  @binder_paths
end

#bowlineObject

Returns the value of attribute bowline.



391
392
393
# File 'lib/bowline/initializer.rb', line 391

def bowline
  @bowline
end

#cache_classesObject

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

Returns the value of attribute copyright.



489
490
491
# File 'lib/bowline/initializer.rb', line 489

def copyright
  @copyright
end

#database_configuration_fileObject

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_loadingObject

Returns the value of attribute dependency_loading.



445
446
447
# File 'lib/bowline/initializer.rb', line 445

def dependency_loading
  @dependency_loading
end

#descriptionObject

Returns the value of attribute description.



477
478
479
# File 'lib/bowline/initializer.rb', line 477

def description
  @description
end

#eager_load_pathsObject

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_globObject

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

#frameworksObject

Returns the value of attribute frameworks.



393
394
395
# File 'lib/bowline/initializer.rb', line 393

def frameworks
  @frameworks
end

#helper_globObject

Returns the value of attribute helper_glob.



458
459
460
# File 'lib/bowline/initializer.rb', line 458

def helper_glob
  @helper_glob
end

#iconObject

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

#idObject

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_globObject

Returns the value of attribute initializer_glob.



460
461
462
# File 'lib/bowline/initializer.rb', line 460

def initializer_glob
  @initializer_glob
end

#log_levelObject

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_pathObject

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

#loggerObject

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_pathObject

Returns the value of attribute marshal_path.



401
402
403
# File 'lib/bowline/initializer.rb', line 401

def marshal_path
  @marshal_path
end

#nameObject

Set the application’s name. This is required.



464
465
466
# File 'lib/bowline/initializer.rb', line 464

def name
  @name
end

#plugin_globObject

Returns the value of attribute plugin_glob.



457
458
459
# File 'lib/bowline/initializer.rb', line 457

def plugin_glob
  @plugin_glob
end

#publisherObject

Returns the value of attribute publisher.



488
489
490
# File 'lib/bowline/initializer.rb', line 488

def publisher
  @publisher
end

#reload_pluginsObject

Returns the value of attribute reload_plugins.



439
440
441
# File 'lib/bowline/initializer.rb', line 439

def reload_plugins
  @reload_plugins
end

#root_pathObject (readonly)

The application’s base directory.



380
381
382
# File 'lib/bowline/initializer.rb', line 380

def root_path
  @root_path
end

#time_zoneObject

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

#urlObject

Returns the value of attribute url.



478
479
480
# File 'lib/bowline/initializer.rb', line 478

def url
  @url
end

#versionObject

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_nilsObject

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_blocksObject

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_configurationObject

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

#helpersObject



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.

Returns:

  • (Boolean)


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.expand_path(::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