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
id[R]
items[R]
link_type[R]
localized[R]
name[R]
raw[R]
required[R]
type[R]
Public Class Methods
new(json)
click to toggle 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
coerce(value, configuration)
click to toggle source
Coerces value to proper type
# 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