Module: CanTango::Configuration::Factory

Included in:
Ability, Engines::Store
Defined in:
lib/cantango/configuration/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_classObject

Returns the value of attribute default_class.



29
30
31
# File 'lib/cantango/configuration/factory.rb', line 29

def default_class
  @default_class
end

Instance Method Details

#call_factory(obj = nil, opts = {}) ⇒ Object



20
21
22
# File 'lib/cantango/configuration/factory.rb', line 20

def call_factory obj = nil, opts = {}
  @factory.respond_to?(:call) ? @factory.call(obj, opts) : @factory
end

#clear!Object



4
5
6
# File 'lib/cantango/configuration/factory.rb', line 4

def clear!
  @factory = nil
end

#default_factory(obj = nil, opts = {}) ⇒ Object



24
25
26
27
# File 'lib/cantango/configuration/factory.rb', line 24

def default_factory obj = nil, opts = {}
  raise "Default factory must be defined" if !default_class
  default_class.new obj, options.merge(opts)
end

#factory(factory = nil) ⇒ Object Also known as: factory=



8
9
10
11
# File 'lib/cantango/configuration/factory.rb', line 8

def factory factory = nil
  raise "Factory must be a callable, either a lambda or Proc" if !callable? factory
  @factory = factory
end

#factory_build(obj = nil, opts = {}) ⇒ Object



15
16
17
18
# File 'lib/cantango/configuration/factory.rb', line 15

def factory_build obj = nil, opts = {}
  factory_method = @factory ? :call_factory : :default_factory
  send(factory_method, obj, opts)
end

#optionsObject



42
43
44
# File 'lib/cantango/configuration/factory.rb', line 42

def options
  @options ? type_options : type_options.merge(@options || {})
end

#options=(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
# File 'lib/cantango/configuration/factory.rb', line 37

def options= options = {}
  raise ArgumentError, "Must be a Hash, was #{options}" if !options.kind_of? Hash
  @options = options
end

#type_optionsObject



46
47
48
# File 'lib/cantango/configuration/factory.rb', line 46

def type_options
  {}
end