case_transform.rb 762 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. module ActivityPub::CaseTransform
  3. class << self
  4. def camel_lower_cache
  5. @camel_lower_cache ||= {}
  6. end
  7. def camel_lower(value)
  8. case value
  9. when Array then value.map { |item| camel_lower(item) }
  10. when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
  11. when Symbol then camel_lower(value.to_s).to_sym
  12. when String
  13. camel_lower_cache[value] ||= if value.start_with?('_:')
  14. '_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower)
  15. else
  16. value.underscore.camelize(:lower)
  17. end
  18. else value
  19. end
  20. end
  21. end
  22. end