闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
762 B

  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