Module: Gorillib::Factory

Defined in:
lib/gorillib/model/type/url.rb,
lib/gorillib/model/factories.rb,
lib/gorillib/model/type/extended.rb

Defined Under Namespace

Classes: ApplyProcFactory, ArrayFactory, BaseFactory, BignumFactory, BinaryFactory, Boolean10Factory, BooleanFactory, ClassFactory, ComplexFactory, ConvertingFactory, DateFactory, EnumerableFactory, EpochTimeFactory, ExceptionFactory, FactoryMismatchError, FalseFactory, FloatFactory, GraciousFloatFactory, GraciousIntegerFactory, GuidFactory, HashFactory, HostnameFactory, IntTimeFactory, IntegerFactory, IpAddressFactory, ModuleFactory, NilFactory, NonConvertingFactory, PathnameFactory, RangeFactory, RationalFactory, RegexpFactory, SetFactory, StringFactory, SymbolFactory, TimeFactory, TrueFactory, UrlFactory

Constant Summary collapse

IdenticalFactory =
::Whatever
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
',fFlL'
FLT_NOT_INT_RE =
/[\.eE]/

Class Method Summary collapse

Class Method Details

.factory_for(type, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/gorillib/model/factories.rb', line 21

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) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/gorillib/model/factories.rb', line 10

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] = ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(type.gsub(/\./, '/'))) )
  else raise ArgumentError, "Don't know which factory makes a #{type}"
  end
end

.register_factory(factory, typenames) ⇒ Object



27
28
29
# File 'lib/gorillib/model/factories.rb', line 27

def self.register_factory(factory, typenames)
  typenames.each{|typename| factories[typename] = factory }
end

.register_factory_klass(factory_klass, typenames) ⇒ Object



31
32
33
# File 'lib/gorillib/model/factories.rb', line 31

def self.register_factory_klass(factory_klass, typenames)
  typenames.each{|typename| factory_klasses[typename] = factory_klass }
end