Namespace

Class/Module Index [+]

Quicksearch

Gorillib::Factory

Constants

FLT_CRUFT_CHARS

In the following, we use eg `Float(val)` and not `val.to_f` – they round-trip things

Float("0x1.999999999999ap-4") # => 0.1
"0x1.999999999999ap-4".to_f   # => 0
FLT_NOT_INT_RE
IdenticalFactory

Public Class Methods

factory_for(type, options={}) click to toggle source
# File lib/gorillib/factories.rb, line 29
def self.factory_for(type, options={})
  return find(type) if options.compact.blank?
  klass = factory_klasses[type] or raise "You can only supply options #{options} to a Factory-mapped class"
  klass.new(options)
end
find(type) click to toggle source
# File lib/gorillib/factories.rb, line 18
def self.find(type)
  case
  when factories.include?(type)               then return factories[type]
  when type.respond_to?(:receive)             then return type
  when type.is_a?(Proc) || type.is_a?(Method) then return Gorillib::Factory::ApplyProcFactory.new(type)
  when type.is_a?(String)                     then
    return( factories[type] = Gorillib::Inflector.constantize(Gorillib::Inflector.camelize(type.gsub(/\./, '/'))) )
  else raise ArgumentError, "Don't know which factory makes a #{type}"
  end
end
make(obj) click to toggle source

Manufactures objects from their raw attributes hash

A hash with a value for `:_type` is dispatched to the corresponding factory Everything else is returned directly

# File lib/gorillib/factories.rb, line 39
def self.make(obj)
  if obj.respond_to?(:has_key?) && (obj.has_key?(:_type) || obj.has_key?('_type'))
    factory = Gorillib::Factory(attrs[:_type])
    factory.receive(obj)
  else
    obj
  end
end
register_factory(factory, typenames) click to toggle source
# File lib/gorillib/factories.rb, line 48
def self.register_factory(factory, typenames)
  typenames.each{|typename| factories[typename] = factory }
end
register_factory_klass(factory_klass, typenames) click to toggle source
# File lib/gorillib/factories.rb, line 52
def self.register_factory_klass(factory_klass, typenames)
  typenames.each{|typename| factory_klasses[typename] = factory_klass }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.