case_transform.rb 908 B

1234567891011121314151617181920212223242526
  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.delete_prefix('_:').underscore.camelize(:lower)}"
  15. elsif LanguagesHelper::ISO_639_1_REGIONAL.key?(value.to_sym)
  16. value
  17. else
  18. value.underscore.camelize(:lower)
  19. end
  20. else value
  21. end
  22. end
  23. end
  24. end