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.



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/bowline/initializer.rb', line 433

def initialize
  set_root_path!
  
  self.frameworks                   = default_frameworks
  self.load_paths                   = default_load_paths
  self.load_once_paths              = default_load_once_paths
  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.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.gems                         = default_gems
  self.gem_path                     = default_gem_path
  self.plugin_glob                  = default_plugin_glob
  self.helper_glob                  = default_helper_glob
  self.initializer_glob             = default_initalizer_glob
  
  self.publisher                    = default_publisher
  self.copyright                    = default_copyright
  self.titanium_version             = default_titanium_version
  
  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.



324
325
326
# File 'lib/bowline/initializer.rb', line 324

def active_record
  @active_record
end

#active_resourceObject

A stub for setting options on ActiveResource::Base.



327
328
329
# File 'lib/bowline/initializer.rb', line 327

def active_resource
  @active_resource
end

#active_supportObject

A stub for setting options on ActiveSupport.



330
331
332
# File 'lib/bowline/initializer.rb', line 330

def active_support
  @active_support
end

#app_config_fileObject

Returns the value of attribute app_config_file.



346
347
348
# File 'lib/bowline/initializer.rb', line 346

def app_config_file
  @app_config_file
end

#binder_pathsObject

Returns the value of attribute binder_paths.



340
341
342
# File 'lib/bowline/initializer.rb', line 340

def binder_paths
  @binder_paths
end

#bowlineObject

Returns the value of attribute bowline.



332
333
334
# File 'lib/bowline/initializer.rb', line 332

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)



338
339
340
# File 'lib/bowline/initializer.rb', line 338

def cache_classes
  @cache_classes
end

Returns the value of attribute copyright.



428
429
430
# File 'lib/bowline/initializer.rb', line 428

def copyright
  @copyright
end

#database_configuration_fileObject

The path to the database configuration file to use. (Defaults to config/database.yml.)



344
345
346
# File 'lib/bowline/initializer.rb', line 344

def database_configuration_file
  @database_configuration_file
end

#descriptionObject

Returns the value of attribute description.



423
424
425
# File 'lib/bowline/initializer.rb', line 423

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 load_paths.



359
360
361
# File 'lib/bowline/initializer.rb', line 359

def eager_load_paths
  @eager_load_paths
end

#frameworksObject

Returns the value of attribute frameworks.



334
335
336
# File 'lib/bowline/initializer.rb', line 334

def frameworks
  @frameworks
end

#gem_pathObject

Returns the value of attribute gem_path.



407
408
409
# File 'lib/bowline/initializer.rb', line 407

def gem_path
  @gem_path
end

#gemsObject

An array of gems that this Bowline application depends on. Bowline will automatically load these gems during installation, and allow you to install any missing gems with:

rake gems:sync

You can add gems with the #gem method.



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

def gems
  @gems
end

#helper_globObject

Returns the value of attribute helper_glob.



416
417
418
# File 'lib/bowline/initializer.rb', line 416

def helper_glob
  @helper_glob
end

#iconObject

Returns the value of attribute icon.



426
427
428
# File 'lib/bowline/initializer.rb', line 426

def icon
  @icon
end

#idObject

Returns the value of attribute id.



421
422
423
# File 'lib/bowline/initializer.rb', line 421

def id
  @id
end

#initializer_globObject

Returns the value of attribute initializer_glob.



418
419
420
# File 'lib/bowline/initializer.rb', line 418

def initializer_glob
  @initializer_glob
end

#load_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.



354
355
356
# File 'lib/bowline/initializer.rb', line 354

def load_once_paths
  @load_once_paths
end

#load_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.



350
351
352
# File 'lib/bowline/initializer.rb', line 350

def load_paths
  @load_paths
end

#log_levelObject

The log level to use for the default Bowline logger.



362
363
364
# File 'lib/bowline/initializer.rb', line 362

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).



366
367
368
# File 'lib/bowline/initializer.rb', line 366

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.



372
373
374
# File 'lib/bowline/initializer.rb', line 372

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



420
421
422
# File 'lib/bowline/initializer.rb', line 420

def name
  @name
end

#plugin_globObject

Returns the value of attribute plugin_glob.



414
415
416
# File 'lib/bowline/initializer.rb', line 414

def plugin_glob
  @plugin_glob
end

#publisherObject

Returns the value of attribute publisher.



424
425
426
# File 'lib/bowline/initializer.rb', line 424

def publisher
  @publisher
end

#reload_pluginsObject

Returns the value of attribute reload_plugins.



378
379
380
# File 'lib/bowline/initializer.rb', line 378

def reload_plugins
  @reload_plugins
end

#root_pathObject (readonly)

The application’s base directory.



321
322
323
# File 'lib/bowline/initializer.rb', line 321

def root_path
  @root_path
end

#sdkObject

Returns the value of attribute sdk.



427
428
429
# File 'lib/bowline/initializer.rb', line 427

def sdk
  @sdk
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.



412
413
414
# File 'lib/bowline/initializer.rb', line 412

def time_zone
  @time_zone
end

#titanium_versionObject

Returns the value of attribute titanium_version.



430
431
432
# File 'lib/bowline/initializer.rb', line 430

def titanium_version
  @titanium_version
end

#urlObject

Returns the value of attribute url.



425
426
427
# File 'lib/bowline/initializer.rb', line 425

def url
  @url
end

#versionObject

Returns the value of attribute version.



422
423
424
# File 'lib/bowline/initializer.rb', line 422

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.



376
377
378
# File 'lib/bowline/initializer.rb', line 376

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.



502
503
504
# File 'lib/bowline/initializer.rb', line 502

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



507
508
509
# File 'lib/bowline/initializer.rb', line 507

def after_initialize_blocks
  @after_initialize_blocks ||= []
end

#app_configObject



482
483
484
485
# File 'lib/bowline/initializer.rb', line 482

def app_config
  require 'erb'
  YAML::load(ERB.new(IO.read(app_config_file)).result) if File.exists?(app_config_file)
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.



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

def database_configuration
  require 'erb'
  YAML::load(ERB.new(IO.read(database_configuration_file)).result) if File.exists?(database_configuration_file)
end

#gem(*args) ⇒ Object

Adds a single Gem dependency to the Bowline application. By default, it will require the library with the same name as the gem. Use :lib to specify a different name.

# gem 'aws-s3', '>= 0.4.0'
# require 'aws/s3'
config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
  :source => "http://code.whytheluckystiff.net"

To require a library be installed, but not attempt to load it, pass :lib => false

config.gem 'qrp', :version => '0.4.1', :lib => false


403
404
405
# File 'lib/bowline/initializer.rb', line 403

def gem(*args)
  @gems << Dependencies::Dependency.new(*args)
end

#helpersObject



495
496
497
# File 'lib/bowline/initializer.rb', line 495

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)


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

def reload_plugins?
  !!@reload_plugins
end

#set_root_path!Object

Set the root_path to APP_ROOT and canonicalize it.



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/bowline/initializer.rb', line 463

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