Module: CanTango::Configuration::Factory
- Included in:
- Ability, Engines::Store
- Defined in:
- lib/cantango/configuration/factory.rb
Instance Attribute Summary collapse
-
#default_class ⇒ Object
Returns the value of attribute default_class.
Instance Method Summary collapse
- #call_factory(obj = nil, opts = {}) ⇒ Object
- #clear! ⇒ Object
- #default_factory(obj = nil, opts = {}) ⇒ Object
- #factory(factory = nil) ⇒ Object (also: #factory=)
- #factory_build(obj = nil, opts = {}) ⇒ Object
- #options ⇒ Object
- #options=(options = {}) ⇒ Object
- #type_options ⇒ Object
Instance Attribute Details
#default_class ⇒ Object
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, .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 |
#options ⇒ Object
42 43 44 |
# File 'lib/cantango/configuration/factory.rb', line 42 def @options ? : .merge(@options || {}) end |
#options=(options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/cantango/configuration/factory.rb', line 37 def = {} raise ArgumentError, "Must be a Hash, was #{}" if !.kind_of? Hash @options = end |
#type_options ⇒ Object
46 47 48 |
# File 'lib/cantango/configuration/factory.rb', line 46 def {} end |