Class: Gum::Factory
- Inherits:
-
Object
- Object
- Gum::Factory
- Defined in:
- lib/gum/factory.rb
Class Method Summary collapse
- .args_to_mapping(args) ⇒ Object
- .build(type, args) ⇒ Object
- .new(type, param, field, options) ⇒ Object
- .normalize_mapping(mapping) ⇒ Object
Class Method Details
.args_to_mapping(args) ⇒ Object
11 12 13 14 15 |
# File 'lib/gum/factory.rb', line 11 def self.args_to_mapping(args) args.inject({}) do |mapping, arg| mapping.update normalize_mapping(arg) end end |
.build(type, args) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/gum/factory.rb', line 3 def self.build(type, args) mapping = args_to_mapping(args) = mapping.delete(:options) mapping.each do |param, field| yield new(type, param, field, ) end end |
.new(type, param, field, options) ⇒ Object
28 29 30 31 |
# File 'lib/gum/factory.rb', line 28 def self.new(type, param, field, ) filter = type.is_a?(Class) ? type : Filters.const_get(type.to_s.camelize, false) filter.new param, field, end |
.normalize_mapping(mapping) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gum/factory.rb', line 17 def self.normalize_mapping(mapping) case mapping when Hash mapping when Array mapping.zip(mapping).to_h else { mapping => mapping } end end |