Module: Lettr::ObjectConverter
- Included in:
- ApiMailing
- Defined in:
- lib/lettr/object_converter.rb
Instance Method Summary collapse
- #evaluate_collections ⇒ Object
- #handle_collection_variable(variable_name, full_variable_name) ⇒ Object
- #handle_methods(methods, hash) ⇒ Object
- #handle_new_collection(context, object_context, collection_name, variable_name) ⇒ Object
- #is_collection_variable?(variable_name) ⇒ Boolean
- #options_to_hash(name) ⇒ Object
Instance Method Details
#evaluate_collections ⇒ Object
56 57 58 59 60 |
# File 'lib/lettr/object_converter.rb', line 56 def evaluate_collections @collections.each do |key, collection| collection.evaluate end end |
#handle_collection_variable(variable_name, full_variable_name) ⇒ Object
66 67 68 |
# File 'lib/lettr/object_converter.rb', line 66 def handle_collection_variable variable_name, full_variable_name @collections[variable_name].add_variable(full_variable_name) end |
#handle_methods(methods, hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lettr/object_converter.rb', line 14 def handle_methods methods, hash method_call = methods.last context = hash object_context = @delivery_options methods.each_with_index do |method, index| case method # collection variable when /(\w+)\[([\w\.]+)\]/ collection_name = $1 variable_name = $2 if method == method_call handle_new_collection context, object_context, collection_name, variable_name else if is_collection_variable? methods[index+1] handle_collection_variable( methods[index+1], methods.join('.') ) break end end # methoden aufruf (letztes element in der kette) when method_call if object_context.class.respond_to? :is_whitelisted? raise SecurityError, "method #{method_call} in class #{object_context.class} not whitelisted" unless object_context.class.is_whitelisted?(method) else warn "no whitelist in class #{object_context.class}" end context[method] = object_context.send(method) # zwischenaufruf else context[method] = {} unless context[method] context = context[method] object_context = index == 0 ? object_context[method] : object_context.send(method) end end end |
#handle_new_collection(context, object_context, collection_name, variable_name) ⇒ Object
50 51 52 53 54 |
# File 'lib/lettr/object_converter.rb', line 50 def handle_new_collection context, object_context, collection_name, variable_name collection = object_context.send(collection_name) context[collection_name] = [] @collections[variable_name] = Lettr::Collection.new collection, context[collection_name] end |
#is_collection_variable?(variable_name) ⇒ Boolean
62 63 64 |
# File 'lib/lettr/object_converter.rb', line 62 def is_collection_variable? variable_name @collections.has_key?( variable_name ) end |
#options_to_hash(name) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/lettr/object_converter.rb', line 3 def name hash = {} @collections = {} @vars[name.to_s].each do |var| methods = var.split('.') handle_methods(methods, hash) end evaluate_collections hash end |