class Contentful::Field
A ContentType’s field schema See www.contentful.com/developers/documentation/content-management-api/#resources-content-types-fields
Constants
- KNOWN_TYPES
-
Coercions from
Contentful
Types to Ruby native types
Attributes
Public Class Methods
Source
# File lib/contentful/field.rb, line 26 def initialize(json) @raw = json @id = json.fetch('id', nil) @name = json.fetch('name', nil) @type = json.fetch('type', nil) @link_type = json.fetch('linkType', nil) @items = json.key?('items') ? Field.new(json.fetch('items', {})) : nil @required = json.fetch('required', false) @localized = json.fetch('localized', false) end
Public Instance Methods
Source
# File lib/contentful/field.rb, line 38 def coerce(value, configuration) return value if type.nil? return value if value.nil? options = {} options[:coercion_class] = KNOWN_TYPES[items.type] unless items.nil? KNOWN_TYPES[type].new(value, options).coerce(configuration) end
Coerces value to proper type