Module: CanTango::Config::Factory

Included in:
Ability
Defined in:
lib/cantango/config/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_classObject

Returns the value of attribute default_class.



35
36
37
# File 'lib/cantango/config/factory.rb', line 35

def default_class
  @default_class
end

Instance Method Details

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



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

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

#clear_factory!Object



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

def clear_factory!
  @factory = nil
end

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



28
29
30
31
32
33
# File 'lib/cantango/config/factory.rb', line 28

def default_factory obj = nil, opts = {}
  clazz_meth = send(:factory_class_method) if respond_to? :factory_class_method
  clazz_meth = :default_class unless clazz_meth && respond_to?(clazz_meth)
  raise "Default factory must be defined via call to ##{clazz_meth}" unless send(clazz_meth)
  send(clazz_meth).new obj, options.merge(opts)
end

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

Raises:

  • (ArgumentError)


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

def factory proc = nil
  raise ArgumentError, "Factory must be a callable (lambda or Proc), was: #{proc}" unless callable? proc
  @factory = proc
end

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



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

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

#get_factoryObject



13
14
15
# File 'lib/cantango/config/factory.rb', line 13

def get_factory
  @factory
end

#optionsObject



48
49
50
# File 'lib/cantango/config/factory.rb', line 48

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

#options=(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
# File 'lib/cantango/config/factory.rb', line 43

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

#type_optionsObject



52
53
54
# File 'lib/cantango/config/factory.rb', line 52

def type_options
  {}
end