Module: Contentful::DatabaseImporter::ResourceFieldClassMethods
- Defined in:
- lib/contentful/database_importer/resource_field_class_methods.rb
Overview
Field related Class Methods for Resource
Instance Method Summary collapse
- #fetch_many_relationship_options(field, options) ⇒ Object (also: #fetch_one_relationship_options)
- #fetch_relationship_options(field, options) ⇒ Object
- #fetch_through_relationship_options(field, options) ⇒ Object
- #field(database_name, options = {}) ⇒ Object
- #fields ⇒ Object
- #prepare_field(database_name, options) ⇒ Object
- #prepare_standard_field_options(database_name, options) ⇒ Object
- #relationship_fields ⇒ Object
Instance Method Details
#fetch_many_relationship_options(field, options) ⇒ Object Also known as: fetch_one_relationship_options
37 38 39 40 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 37 def (field, ) field[:id_field] = .fetch(:id_field) field[:key] = .fetch(:key) end |
#fetch_relationship_options(field, options) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 51 def (field, ) field[:relationship] = .fetch(:relationship) send( "fetch_#{options.fetch(:relationship)}_relationship_options", field, ) end |
#fetch_through_relationship_options(field, options) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 43 def (field, ) field[:through] = .fetch(:through) field[:primary_id_field] = .fetch(:primary_id_field) field[:foreign_id_field] = .fetch(:foreign_id_field) field[:primary_key] = .fetch(:primary_key) field[:foreign_key] = .fetch(:foreign_key) end |
#field(database_name, options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 5 def field(database_name, = {}) @fields ||= [] @fields << prepare_field(database_name, ) end |
#fields ⇒ Object
10 11 12 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 10 def fields @fields || [] end |
#prepare_field(database_name, options) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 29 def prepare_field(database_name, ) field = (database_name, ) field[:item_type] = .fetch(:item_type) if field[:type] == :array (field, ) if .fetch(:relationship, false) field end |
#prepare_standard_field_options(database_name, options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 18 def (database_name, ) { db_name: database_name, maps_to: .fetch(:maps_to, database_name), name: .fetch(:name, database_name), type: .fetch(:type), pre_process: .fetch(:pre_process, nil), exclude_from_output: .fetch(:exclude_from_output, false) } end |
#relationship_fields ⇒ Object
14 15 16 |
# File 'lib/contentful/database_importer/resource_field_class_methods.rb', line 14 def relationship_fields @fields.select { |f| resource?(f[:type]) } end |