Class: Stringex::Configuration::Base
- Inherits:
-
Object
- Object
- Stringex::Configuration::Base
- Defined in:
- lib/stringex/configuration/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
- .configure {|configurator| ... } ⇒ Object
- .system_wide_customizations ⇒ Object
- .unconfigure! ⇒ Object
Instance Method Summary collapse
-
#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.
-
#initialize(local_options = {}) ⇒ Base
constructor
A new instance of Base.
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( = {}) current_settings = default_settings.merge(system_wide_customizations) current_settings.merge! @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
.configure {|configurator| ... } ⇒ Object
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 |
.unconfigure! ⇒ Object
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 |