Module: IronAdmin::Adapters::Http::TypeInferrer
- Defined in:
- lib/iron_admin/adapters/http/type_inferrer.rb
Overview
Infers IronAdmin field types from JSON values.
Used for auto-discovery: the adapter fetches the first API response and uses this class to determine column types from the JSON data, matching IronAdmin's convention-over-configuration philosophy.
Constant Summary collapse
- ISO8601_DATETIME =
/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/- ISO8601_DATE =
/\A\d{4}-\d{2}-\d{2}\z/
Class Method Summary collapse
-
.infer(value) ⇒ Symbol
Infers the IronAdmin type symbol from a JSON value.
-
.infer_columns(data) ⇒ Array<ColumnDescriptor>
Infers column descriptors from a JSON hash (one record).
Class Method Details
.infer(value) ⇒ Symbol
Infers the IronAdmin type symbol from a JSON value.
19 20 21 22 23 24 25 26 27 |
# File 'lib/iron_admin/adapters/http/type_inferrer.rb', line 19 def self.infer(value) case value when Integer, Float then :number when TrueClass, FalseClass then :boolean when Hash, Array then :json when String then infer_string_type(value) else :string end end |
.infer_columns(data) ⇒ Array<ColumnDescriptor>
Infers column descriptors from a JSON hash (one record).
33 34 35 |
# File 'lib/iron_admin/adapters/http/type_inferrer.rb', line 33 def self.infer_columns(data) data.map { |key, value| ColumnDescriptor.new(key.to_s, infer(value)) } end |