Class: Backyard::Configuration
- Inherits:
-
Object
- Object
- Backyard::Configuration
- Defined in:
- lib/backyard/configuration.rb
Defined Under Namespace
Classes: Model
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
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(*args, &block) ⇒ Object
- #use_adapter(adapter) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 9 |
# File 'lib/backyard/configuration.rb', line 6 def initialize @model_configuration ||= {} @adapter ||= :factory_girl end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/backyard/configuration.rb', line 4 def adapter @adapter end |
Instance Method Details
#adapter_instance ⇒ Object
40 41 42 |
# File 'lib/backyard/configuration.rb', line 40 def adapter_instance @adapter_instance ||= adapter_klass.new end |
#config_for(model_type) ⇒ Object
36 37 38 |
# File 'lib/backyard/configuration.rb', line 36 def config_for(model_type) @model_configuration[model_type] ||= Model.new end |
#name_attribute(attribute, options = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/backyard/configuration.rb', line 11 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(*args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/backyard/configuration.rb', line 19 def name_for(*args, &block) = args. args.each do |model_type| klass = adapter_instance.class_for_type(model_type) if .has_key?(:attribute) config_for(klass).name_attributes << [:attribute] else config_for(klass).name_blocks << block end end end |
#use_adapter(adapter) ⇒ Object
32 33 34 |
# File 'lib/backyard/configuration.rb', line 32 def use_adapter(adapter) @adapter = adapter end |