class Contentful::Converter::ContentTypesStructureCreator
Attributes
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 7 def initialize(config) @config = config end
Public Instance Methods
create_content_type_json_file(content_type_name, values)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 11 def create_content_type_json_file(content_type_name, values) collection = { id: values[:id], name: values[:name], description: values[:description], displayField: values[:displayField], fields: create_fields(values[:fields]) } write_json_to_file("#{config.collections_dir}/#{content_type_name}.json", collection) end
create_field(field, value)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 34 def create_field(field, value) value.is_a?(Hash) ? value[:id] : field end
create_fields(fields)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 22 def create_fields(fields) fields.each_with_object([]) do |(field, value), results| results << { name: create_field(field, value).capitalize, id: create_field(field, value), type: create_type_field(value), link_type: create_link_type_field(value), link: create_link_field(value) }.compact end end
create_link_field(value)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 46 def create_link_field(value) value.is_a?(Hash) ? value[:link] : nil end
create_link_type_field(value)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 38 def create_link_type_field(value) value.is_a?(Hash) ? value[:link_type] : nil end
create_type_field(value)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 42 def create_type_field(value) value.is_a?(Hash) ? value[:type] : value end
write_json_to_file(path, data)
click to toggle source
# File lib/converters/content_types_structure_creator.rb, line 50 def write_json_to_file(path, data) File.open(path, 'w') do |file| file.write(JSON.pretty_generate(data)) end end