Class: BridgetownDirectus::Configuration::CollectionConfig
- Inherits:
-
Object
- Object
- BridgetownDirectus::Configuration::CollectionConfig
- Defined in:
- lib/bridgetown_directus/configuration.rb
Overview
Collection configuration class
Instance Attribute Summary collapse
-
#default_query ⇒ Object
Set up accessors for collection configuration properties.
-
#endpoint ⇒ Object
Set up accessors for collection configuration properties.
-
#fields ⇒ Object
Set up accessors for collection configuration properties.
-
#layout ⇒ Object
Set up accessors for collection configuration properties.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource_type ⇒ Object
Set up accessors for collection configuration properties.
-
#translatable_fields ⇒ Object
Set up accessors for collection configuration properties.
-
#translations_enabled ⇒ Object
Set up accessors for collection configuration properties.
Instance Method Summary collapse
-
#enable_translations(fields = []) ⇒ void
Enable translations for this collection.
-
#field(bridgetown_field, directus_field, &converter) ⇒ void
Define a field mapping with optional converter.
-
#initialize(name) ⇒ CollectionConfig
constructor
Initialize a new collection configuration.
-
#path(item) ⇒ String
Generate the resource path for a given item.
Constructor Details
#initialize(name) ⇒ CollectionConfig
Initialize a new collection configuration
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bridgetown_directus/configuration.rb', line 37 def initialize(name) @name = name @fields = {} @default_query = {} @resource_type = :posts @layout = "post" @translations_enabled = false @translatable_fields = [] @endpoint = nil end |
Instance Attribute Details
#default_query ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def default_query @default_query end |
#endpoint ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def endpoint @endpoint end |
#fields ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def fields @fields end |
#layout ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def layout @layout end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/bridgetown_directus/configuration.rb', line 33 def name @name end |
#resource_type ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def resource_type @resource_type end |
#translatable_fields ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def translatable_fields @translatable_fields end |
#translations_enabled ⇒ Object
Set up accessors for collection configuration properties
49 50 51 |
# File 'lib/bridgetown_directus/configuration.rb', line 49 def translations_enabled @translations_enabled end |
Instance Method Details
#enable_translations(fields = []) ⇒ void
This method returns an undefined value.
Enable translations for this collection
67 68 69 70 |
# File 'lib/bridgetown_directus/configuration.rb', line 67 def enable_translations(fields = []) @translations_enabled = true @translatable_fields = fields end |
#field(bridgetown_field, directus_field, &converter) ⇒ void
This method returns an undefined value.
Define a field mapping with optional converter
57 58 59 60 61 62 |
# File 'lib/bridgetown_directus/configuration.rb', line 57 def field(bridgetown_field, directus_field, &converter) @fields[bridgetown_field] = { directus_field: directus_field.to_s, converter: converter, } end |
#path(item) ⇒ String
Generate the resource path for a given item
75 76 77 78 79 |
# File 'lib/bridgetown_directus/configuration.rb', line 75 def path(item) # Default: /:resource_type/:slug/index.html slug = item["slug"] || item[:slug] || item["id"] || item[:id] "/#{resource_type}/#{slug}/index.html" end |