Class: Pageflow::EntryStructuredDataTypes
- Inherits:
-
Object
- Object
- Pageflow::EntryStructuredDataTypes
- Defined in:
- lib/pageflow/entry_structured_data_types.rb
Overview
Registry for structured data types that can be used in entries.
Instance Method Summary collapse
- #for(entry) ⇒ Object private
-
#initialize ⇒ EntryStructuredDataTypes
constructor
A new instance of EntryStructuredDataTypes.
- #names ⇒ Object private
-
#register(name, callable, options = {}) ⇒ Object
Register a structured data type for entries.
Constructor Details
#initialize ⇒ EntryStructuredDataTypes
Returns a new instance of EntryStructuredDataTypes.
4 5 6 7 |
# File 'lib/pageflow/entry_structured_data_types.rb', line 4 def initialize @types = {} @default_name = nil end |
Instance Method Details
#for(entry) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 40 41 |
# File 'lib/pageflow/entry_structured_data_types.rb', line 36 def for(entry) structured_data_type = @types[entry.structured_data_type_name] || @types[@default_name] structured_data_type ? structured_data_type.call(entry) : {} end |
#names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/pageflow/entry_structured_data_types.rb', line 31 def names @types.keys end |
#register(name, callable, options = {}) ⇒ Object
Register a structured data type for entries.
25 26 27 28 |
# File 'lib/pageflow/entry_structured_data_types.rb', line 25 def register(name, callable, = {}) @types[name.to_s] = callable @default_name = name.to_s if [:default] end |