Sha256: 6cd752a087a8b9a4d63f78e9b6375dbb0e806ab833521233be2666cd3569401b
Contents?: true
Size: 1.38 KB
Versions: 22
Compression:
Stored size: 1.38 KB
Contents
module CanTango class Configuration module Factory def clear! @factory = nil end def factory factory = nil raise "Factory must be a callable, either a lambda or Proc" if !callable? factory @factory = factory end alias_method :factory=, :factory def factory_build obj = nil, opts = {} factory_method = @factory ? :call_factory : :default_factory send(factory_method, obj, opts) end def call_factory obj = nil, opts = {} @factory.respond_to?(:call) ? @factory.call(obj, opts) : @factory end def default_factory obj = nil, opts = {} raise "Default factory must be defined" if !default_class default_class.new obj, options.merge(opts) end attr_reader :default_class # must be a Class of type Cache (Base?) def default_class= clazz raise ArgumentError, "default must be a Class" if !is_class? clazz @default_class = clazz end def options= options = {} raise ArgumentError, "Must be a Hash, was #{options}" if !options.kind_of? Hash @options = options end def options @options ? type_options : type_options.merge(@options || {}) end def type_options {} end protected def callable? obj obj && obj.respond_to?(:call) end end end end
Version data entries
22 entries across 22 versions & 1 rubygems