Class: Contentful::Management::Field
- Inherits:
-
Object
- Object
- Contentful::Management::Field
- Includes:
- Resource
- Defined in:
- lib/contentful/management/field.rb
Overview
A ContentType’s field schema
Constant Summary
Constants included from Resource
Instance Attribute Summary
Attributes included from Resource
#client, #default_locale, #properties, #raw_object, #request
Class Method Summary collapse
Instance Method Summary collapse
-
#deep_merge!(field) ⇒ Object
Takes a field object of content type Merges existing properties, items and validations of field with new one.
-
#parse_value(key, value) ⇒ Object
Return parsed value of field object.
-
#properties_to_hash ⇒ Object
Extract values of field to hash.
Methods included from Resource
#array?, #fields, #initialize, #inspect, #nested_locale_fields?, #sys
Class Method Details
.value_exists?(value) ⇒ Boolean
46 47 48 |
# File 'lib/contentful/management/field.rb', line 46 def self.value_exists?(value) value.respond_to?(:empty?) && !value.empty? || !value.respond_to?(:empty?) && value end |
Instance Method Details
#deep_merge!(field) ⇒ Object
Takes a field object of content type Merges existing properties, items and validations of field with new one
21 22 23 24 25 |
# File 'lib/contentful/management/field.rb', line 21 def deep_merge!(field) merge_properties(field.properties) merge_items(field.items) merge_validations(field.validations) end |
#parse_value(key, value) ⇒ Object
Return parsed value of field object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/contentful/management/field.rb', line 35 def parse_value(key, value) case key when :items value.properties_to_hash if type == 'Array' && value.is_a?(Field) when :validations validations_to_hash(value) if value.is_a?(::Array) else value if self.class.value_exists?(value) end end |
#properties_to_hash ⇒ Object
Extract values of field to hash
28 29 30 31 32 |
# File 'lib/contentful/management/field.rb', line 28 def properties_to_hash properties.each_with_object({}) do |(key, value), results| results[key] = parse_value(key, value) end end |