Class: WCC::Contentful::ContentTypeIndexer
- Inherits:
-
Object
- Object
- WCC::Contentful::ContentTypeIndexer
- Includes:
- Helpers
- Defined in:
- lib/wcc/contentful/content_type_indexer.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#create_asset_type ⇒ Object
hardcoded because the Asset type is a “magic type” in their system.
- #create_type(content_type_id, fields) ⇒ Object
- #index(content_type) ⇒ Object
-
#initialize ⇒ ContentTypeIndexer
constructor
A new instance of ContentTypeIndexer.
Methods included from Helpers
#constant_from_content_type, #content_type_from_constant, #content_type_from_raw, #shared_prefix
Constructor Details
#initialize ⇒ ContentTypeIndexer
Returns a new instance of ContentTypeIndexer.
11 12 13 14 15 |
# File 'lib/wcc/contentful/content_type_indexer.rb', line 11 def initialize @types = IndexedRepresentation.new({ 'Asset' => create_asset_type }) end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
9 10 11 |
# File 'lib/wcc/contentful/content_type_indexer.rb', line 9 def types @types end |
Instance Method Details
#create_asset_type ⇒ Object
hardcoded because the Asset type is a “magic type” in their system
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wcc/contentful/content_type_indexer.rb', line 43 def create_asset_type IndexedRepresentation::ContentType.new({ name: 'Asset', content_type: 'Asset', fields: { 'title' => { name: 'title', type: :String }, 'description' => { name: 'description', type: :String }, 'file' => { name: 'file', type: :Json } } }) end |
#create_type(content_type_id, fields) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wcc/contentful/content_type_indexer.rb', line 28 def create_type(content_type_id, fields) content_type = IndexedRepresentation::ContentType.new({ name: constant_from_content_type(content_type_id), content_type: content_type_id }) fields.each do |f| field = create_field(f) content_type.fields[field.name] = field end content_type end |
#index(content_type) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wcc/contentful/content_type_indexer.rb', line 17 def index(content_type) content_type = if content_type.respond_to?(:fields) create_type(content_type.id, content_type.fields) else create_type(content_type.dig('sys', 'id'), content_type['fields']) end @types[content_type.content_type] = content_type end |