Class: Stringex::Configuration::Base
- Inherits:
-
Object
- Object
- Stringex::Configuration::Base
show all
- Defined in:
- lib/stringex/configuration/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(local_options = {}) ⇒ 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
#settings ⇒ Object
Returns the value of attribute settings.
4
5
6
|
# File 'lib/stringex/configuration/base.rb', line 4
def settings
@settings
end
|
Class Method Details
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_customizations ⇒ Object
34
35
36
|
# File 'lib/stringex/configuration/base.rb', line 34
def self.system_wide_customizations
@system_wide_customizations ||= {}
end
|
38
39
40
|
# File 'lib/stringex/configuration/base.rb', line 38
def self.unconfigure!
@system_wide_customizations = {}
end
|
Instance Method Details
#adapter ⇒ Object
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
|