Class: Backyard::Configuration
- Inherits:
-
Object
- Object
- Backyard::Configuration
- Defined in:
- lib/backyard/configuration.rb
Defined Under Namespace
Classes: Model
Instance Method Summary collapse
- #adapter_instance ⇒ Object
- #config_for(model_type) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #name_attribute(attribute, options = {}) ⇒ Object
- #name_for(*model_types, &block) ⇒ Object
- #use_adapter(adapter) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
4 5 6 |
# File 'lib/backyard/configuration.rb', line 4 def initialize @model_configuration ||= {} end |
Instance Method Details
#adapter_instance ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/backyard/configuration.rb', line 31 def adapter_instance return @adapter_instance if @adapter_instance @adapter ||= :factory_girl require File.join('backyard', 'adapter', "#{@adapter}") adapter_class = @adapter.to_s.split('_').map!{ |w| w.capitalize }.join @adapter_instance = eval "Backyard::Adapter::#{adapter_class}.new" end |
#config_for(model_type) ⇒ Object
27 28 29 |
# File 'lib/backyard/configuration.rb', line 27 def config_for(model_type) @model_configuration[model_type] ||= Model.new end |
#name_attribute(attribute, options = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/backyard/configuration.rb', line 8 def name_attribute(attribute, = {}) raise "missing the :for options" unless .has_key?(:for) [*[:for]].each do |model_type| model = adapter_instance.class_for_type(model_type) config_for(model).name_attributes << attribute end end |
#name_for(*model_types, &block) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/backyard/configuration.rb', line 16 def name_for(*model_types, &block) model_types.each do |model_type| klass = adapter_instance.class_for_type(model_type) config_for(klass).name_blocks << block end end |
#use_adapter(adapter) ⇒ Object
23 24 25 |
# File 'lib/backyard/configuration.rb', line 23 def use_adapter(adapter) @adapter = adapter end |