Module: Forem::Util
- Defined in:
- lib/forem/util.rb
Overview
Utility helpers used internally by the forem-ruby library.
These methods are not part of the public API surface for end users but are documented here for contributors and library maintainers.
Class Method Summary collapse
-
.convert_to_forem_object(value) ⇒ ForemObject, ...
Recursively convert a raw Ruby value into the appropriate Forem type.
Class Method Details
.convert_to_forem_object(value) ⇒ ForemObject, ...
Recursively convert a raw Ruby value into the appropriate Forem type.
The conversion rules are:
Hash→ ForemObject (via ForemObject.construct_from)Array→ Array with each element passed through this method- anything else → returned unchanged
This method is called during attribute assignment in ForemObject so that nested API response hashes automatically become ForemObject instances with dynamic attribute access.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/forem/util.rb', line 32 def self.convert_to_forem_object(value) case value when Hash ForemObject.construct_from(value) when Array value.map { |v| convert_to_forem_object(v) } else value end end |