Class: Releaf::Content::Configuration
- Inherits:
-
Object
- Object
- Releaf::Content::Configuration
- Defined in:
- lib/releaf/content/configuration.rb
Instance Method Summary collapse
- #controller_names ⇒ Object
- #controllers ⇒ Object
- #default_model ⇒ Object
- #model_names ⇒ Object
- #models ⇒ Object
- #resources=(value) ⇒ Object
- #routing ⇒ Object
- #verify_resources_config(resource_config) ⇒ Object
Instance Method Details
#controller_names ⇒ Object
46 47 48 |
# File 'lib/releaf/content/configuration.rb', line 46 def controller_names @controller_names ||= resources.values.map { || [:controller] } end |
#controllers ⇒ Object
42 43 44 |
# File 'lib/releaf/content/configuration.rb', line 42 def controllers controller_names.map(&:constantize) end |
#default_model ⇒ Object
38 39 40 |
# File 'lib/releaf/content/configuration.rb', line 38 def default_model models.first end |
#model_names ⇒ Object
34 35 36 |
# File 'lib/releaf/content/configuration.rb', line 34 def model_names @model_names ||= resources.keys end |
#models ⇒ Object
30 31 32 |
# File 'lib/releaf/content/configuration.rb', line 30 def models model_names.map(&:constantize) end |
#resources=(value) ⇒ Object
6 7 8 9 |
# File 'lib/releaf/content/configuration.rb', line 6 def resources=(value) verify_resources_config(value) super end |
#routing ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/releaf/content/configuration.rb', line 50 def routing @routing ||= resources.map do | node_class_name, | routing = [:routing] || {} routing[:site] ||= nil routing[:constraints] ||= nil [ node_class_name, routing ] end.to_h end |
#verify_resources_config(resource_config) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/releaf/content/configuration.rb', line 11 def verify_resources_config(resource_config) # perform some basic config structure validation unless resource_config.is_a? Hash raise Releaf::Error, "Releaf.application.config.content.resources must be a Hash" end resource_config.each do | key, values | unless key.is_a? String raise Releaf::Error, "Releaf.application.config.content.resources must have string keys" end unless values.is_a? Hash raise Releaf::Error, "#{key} in Releaf.application.config.content.resources must have a hash value" end unless values[:controller].is_a? String raise Releaf::Error, "#{key} in Releaf.application.config.content.resources must have controller class specified as a string" end end end |