Class: WiserTrails::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wiser_trails/config.rb

Overview

Class used to initialize configuration object.

Defined Under Namespace

Classes: Block

Constant Summary collapse

@@orm =
:active_record

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
14
# File 'lib/wiser_trails/config.rb', line 11

def initialize
  # Indicates whether WiserTrails is enabled globally
  @enabled  = true
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



7
8
9
# File 'lib/wiser_trails/config.rb', line 7

def enabled
  @enabled
end

Class Method Details

.orm(orm = nil) ⇒ Object

Set the ORM for use by WiserTrails.



33
34
35
# File 'lib/wiser_trails/config.rb', line 33

def self.orm(orm = nil)
  @@orm = (orm ? orm.to_sym : false) || @@orm
end

.orm=(orm = nil) ⇒ Object

alias for #orm

See Also:



39
40
41
# File 'lib/wiser_trails/config.rb', line 39

def self.orm=(orm = nil)
  orm(orm)
end

.set(&block) ⇒ Object

Evaluates given block to provide DSL configuration.

Examples:

Initializer for Rails

WiserTrails::Config.set do
  orm :mongo_mapper
  enabled false
end


22
23
24
25
26
27
28
29
30
# File 'lib/wiser_trails/config.rb', line 22

def self.set &block
  b = Block.new
  b.instance_eval &block
  orm = b.instance_variable_get(:@orm)
  @@orm = orm unless orm.nil?
  enabled = b.instance_variable_get(:@en)
  instance
  instance.instance_variable_set(:@enabled, enabled) unless enabled.nil?
end

Instance Method Details

#orm(orm = nil) ⇒ Object

instance version of #orm

See Also:



45
46
47
# File 'lib/wiser_trails/config.rb', line 45

def orm(orm=nil)
  self.class.orm(orm)
end