Class: Releaf::Content::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/releaf/content/configuration.rb

Instance Method Summary collapse

Instance Method Details

#controller_namesObject



46
47
48
# File 'lib/releaf/content/configuration.rb', line 46

def controller_names
  @controller_names ||=  resources.values.map { |options| options[:controller] }
end

#controllersObject



42
43
44
# File 'lib/releaf/content/configuration.rb', line 42

def controllers
  controller_names.map(&:constantize)
end

#default_modelObject



38
39
40
# File 'lib/releaf/content/configuration.rb', line 38

def default_model
  models.first
end

#model_namesObject



34
35
36
# File 'lib/releaf/content/configuration.rb', line 34

def model_names
  @model_names ||= resources.keys
end

#modelsObject



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

#routingObject



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, options |
    routing = options[: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