Nessuna descrizione http://j1x-huginn.herokuapp.com

json_path_options_overwritable.rb 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module JsonPathOptionsOverwritable
  2. extend ActiveSupport::Concern
  3. # Using this concern allows providing optional `<attribute>_path` options hash
  4. # attributes which will then (if not blank) be interpolated using the provided JSONPath.
  5. #
  6. # Example options Hash:
  7. # {
  8. # name: 'Huginn',
  9. # name_path: '$.name',
  10. # title: 'Hello from Huginn'
  11. # title_path: ''
  12. # }
  13. # Example event payload:
  14. # {
  15. # name: 'dynamic huginn'
  16. # }
  17. # calling agent.merge_json_path_options(event) returns the following hash:
  18. # {
  19. # name: 'dynamic huginn'
  20. # title: 'Hello from Huginn'
  21. # }
  22. private
  23. def merge_json_path_options(event)
  24. options.select { |k, v| options_with_path.include? k}.tap do |merged_options|
  25. options_with_path.each do |a|
  26. merged_options[a] = select_option(event, a)
  27. end
  28. end
  29. end
  30. def select_option(event, a)
  31. if options[a.to_s + '_path'].present?
  32. Utils.value_at(event.payload, options[a.to_s + '_path'])
  33. else
  34. options[a]
  35. end
  36. end
  37. end