Class: Reactive::Configuration

Inherits:
OrderedOptions
  • Object
show all
Defined in:
lib/reactive-core/initializer.rb

Overview

Holds the configuration of the framework and plugins.

The configuration object is a hash-like object with access to values with accessors. So these are equivalent:

config[:use_donuts] = true
config.use_donuts = true

It is populated by the framework itself, plugins and also the application through the config/config.rb file and its specialized config/environments/*.rb forms.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Configuration

Returns a new instance of Configuration.



105
106
107
108
109
110
# File 'lib/reactive-core/initializer.rb', line 105

def initialize(*args)
  super()
  self[:paths] = {}
  self[:gems] = []
  parse(args.first) if args.first
end

Instance Method Details

#app_gem_spec(spec = nil, &block) ⇒ Object

:nodoc:



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/reactive-core/initializer.rb', line 155

def app_gem_spec(spec = nil, &block) # :nodoc:
  @app_gem_spec = block if block
  if @app_gem_spec
    if spec
      @app_gem_spec.call(spec)
    else
      options = OrderedOptions.new
      @app_gem_spec.call(options)
      options
    end
  end
end

#gem(name, options = {}) ⇒ Object

Adds a single Gem dependency to the reactive application. You may pass :init => :rails to specifiy that the plugin should be initialized through the rails init code. Note that it is not assured to work.

config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0'
config.gem 'acts_as_tree', :init => :rails


148
149
150
151
152
153
# File 'lib/reactive-core/initializer.rb', line 148

def gem(name, options = {})
  self[:gems] << Reactive::GemDependency.new(name, options)
  
  name = name.gsub(/\W/, '_').squeeze('_')
  self[name] = OrderedOptions.new
end

#merge(options = nil, &block) ⇒ Object

Merges the passed options with the configuration. Pass a hash-like object for the options. You may either pass a block which will be yielded with a fresh configuration object that will be merged after the end of the block.

Raises:

  • (ArgumentError)


116
117
118
119
120
121
122
123
124
# File 'lib/reactive-core/initializer.rb', line 116

def merge(options = nil, &block)
  raise ArgumentError, "Pass either an options object or a block, not both!" unless options.nil? ^ block.nil?
  block.call(options = Configuration.new) if block
  options.each {|key, value| self[key] = value }
  
  # special handling for paths and gems
  (options.paths || {}).each {|type, path| self[:paths][type] = path }
  (options.gems || []).each {|gem| self[:gems] << gem }
end

#reverse_merge(options = nil, &block) ⇒ Object

Reverse merge the passed options with the configuration. See #merge for details about the arguments. A reverse merge is a non destructive merge, that is if a value already exists in the current configuration it has precedence over the one you pass in the arguments.

Raises:

  • (ArgumentError)


129
130
131
132
133
134
135
136
137
138
# File 'lib/reactive-core/initializer.rb', line 129

def reverse_merge(options = nil, &block)
  raise ArgumentError, "Pass either an options object or a block, not both!" unless options.nil? ^ block.nil?
  block.call(options = Configuration.new) if block
  the_keys = self.keys
  options.each {|key, value| self[key] = value unless the_keys.include?(key) }
  
  # special handling for paths and gems
  (options.paths || {}).each {|type, path| self[:paths][type] = path unless self[:paths][type] }
  (options.gems || []).each {|gem| self[:gems] << gem }
end

#root_dir=(value) ⇒ Object

Defines the application root. Normally the boot process will take care of it.



169
170
171
# File 'lib/reactive-core/initializer.rb', line 169

def root_dir=(value) # :nodoc:
  self[:root_dir] = File.expand_path(value)
end