Module: CanTango::Config::Factory
- Included in:
- Ability
- Defined in:
- lib/cantango/config/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_factory! ⇒ Object
- #default_factory(obj = nil, opts = {}) ⇒ Object
- #factory(proc = nil) ⇒ Object (also: #factory=)
- #factory_build(obj = nil, opts = {}) ⇒ Object
- #get_factory ⇒ Object
- #options ⇒ Object
- #options=(options = {}) ⇒ Object
- #type_options ⇒ Object
Instance Attribute Details
#default_class ⇒ Object
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, .merge(opts) end |
#factory(proc = nil) ⇒ Object Also known as: factory=
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_factory ⇒ Object
13 14 15 |
# File 'lib/cantango/config/factory.rb', line 13 def get_factory @factory end |
#options ⇒ Object
48 49 50 |
# File 'lib/cantango/config/factory.rb', line 48 def @options ? : .merge(@options || {}) end |
#options=(options = {}) ⇒ Object
43 44 45 46 |
# File 'lib/cantango/config/factory.rb', line 43 def = {} raise ArgumentError, "Must be a Hash, was #{}" if !.kind_of? Hash @options = end |
#type_options ⇒ Object
52 53 54 |
# File 'lib/cantango/config/factory.rb', line 52 def {} end |