Class: Backyard::Configuration

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

Defined Under Namespace

Classes: Model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#adapterObject (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_instanceObject



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, options = {})
  raise "missing the :for options" unless options.has_key?(:for)
  [*options[: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)
  options = args.extract_options!
  args.each do |model_type|
    klass = adapter_instance.class_for_type(model_type)

    if options.has_key?(:attribute)
      config_for(klass).name_attributes << options[: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