class FactoryGirlLibrary::Library

Public Class Methods

new() click to toggle source
# File lib/factory_girl_library/library.rb, line 5
def initialize
  @library = {}.with_indifferent_access
  @registration_queue = []
end

Public Instance Methods

clear() click to toggle source
# File lib/factory_girl_library/library.rb, line 29
def clear
  @library.clear

  while object = @registration_queue.pop
    object.destroy
  end
end
get(name, opts = {}) click to toggle source
# File lib/factory_girl_library/library.rb, line 19
def get name, opts = {}
  @library[name].tap do |object|
    update(object, opts)
  end
end
register(name, object) click to toggle source
# File lib/factory_girl_library/library.rb, line 10
def register name, object
  @library[name] = object
  @registration_queue.push(object)
end
registered?(name) click to toggle source
# File lib/factory_girl_library/library.rb, line 15
def registered? name
  @library.has_key?(name)
end
reload(object) click to toggle source
# File lib/factory_girl_library/library.rb, line 25
def reload object
  object.reload if @library.value?(object) and object.respond_to?(:reload)
end

Private Instance Methods

update(obj, opts) click to toggle source
# File lib/factory_girl_library/library.rb, line 39
def update obj, opts
  if obj && opts.present?
    opts.each do |key, value|
      obj.send("#{key}=", value)
    end

    obj.save!
  end

  obj
end