Class: Stringex::Configuration::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/stringex/configuration/base.rb

Direct Known Subclasses

ActsAsUrl, StringExtensions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
# File 'lib/stringex/configuration/base.rb', line 6

def initialize(local_options = {})
  current_settings = default_settings.merge(system_wide_customizations)
  current_settings.merge! local_options

  @settings = OpenStruct.new(current_settings)
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



4
5
6
# File 'lib/stringex/configuration/base.rb', line 4

def settings
  @settings
end

Class Method Details

.configure {|configurator| ... } ⇒ Object

Yields:

  • (configurator)


29
30
31
32
# File 'lib/stringex/configuration/base.rb', line 29

def self.configure(&block)
  configurator = Stringex::Configuration::Configurator.new(self)
  yield configurator
end

.system_wide_customizationsObject



34
35
36
# File 'lib/stringex/configuration/base.rb', line 34

def self.system_wide_customizations
  @system_wide_customizations ||= {}
end

.unconfigure!Object



38
39
40
# File 'lib/stringex/configuration/base.rb', line 38

def self.unconfigure!
  @system_wide_customizations = {}
end

Instance Method Details

#adapterObject

NOTE: This does not cache itself so that instance and class can be cached on the adapter without worrying about thread safety or race conditions



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stringex/configuration/base.rb', line 15

def adapter
  adapter_name = settings.adapter || Stringex::ActsAsUrl::Adapter.first_available
  case adapter_name
  when Class
    adapter_name.send :new, self
  when :active_record
    Stringex::ActsAsUrl::Adapter::ActiveRecord.new self
  when :mongoid
    Stringex::ActsAsUrl::Adapter::Mongoid.new self
  else
    raise ArgumentError, "#{adapter_name} is not a defined ActsAsUrl adapter. Please feel free to implement your own and submit it back upstream."
  end
end