Class: Neewom::Collection
- Inherits:
-
Object
- Object
- Neewom::Collection
- Defined in:
- lib/neewom/collection.rb
Constant Summary collapse
- SEQ_KEY =
"neewom|value|"- MOD_KEY =
"|mods:"
Class Method Summary collapse
- .build_for_field(field, bind) ⇒ Object
- .deserialize(param) ⇒ Object
- .serialize(value, mods = "") ⇒ Object
Class Method Details
.build_for_field(field, bind) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/neewom/collection.rb', line 6 def self.build_for_field(field, bind) if field.collection_params.present? method_params = field.collection_params.map do |param| if param.start_with?(SEQ_KEY) deserialize(param) else eval param.to_s, bind end end field.collection_klass.constantize.public_send(field.collection_method, *method_params) else field.collection_klass.constantize.public_send(field.collection_method) end end |
.deserialize(param) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/neewom/collection.rb', line 22 def self.deserialize(param) token = param.gsub(SEQ_KEY, "") value, mods = token.split(MOD_KEY) value = JSON.parse(value) value = mods.split('.').reduce(value) { |acc, mod| acc.public_send(mod) } if mods.present? value end |