Class: Releaf::Configuration

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.normalize_controllers(list) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
# File 'lib/releaf/configuration.rb', line 83

def self.normalize_controllers(list)
  list.map do |item|
    if item.is_a?(Hash) && item.has_key?(:items)
      ControllerGroupDefinition.new(item)
    elsif item.is_a?(Hash) || item.is_a?(String)
      ControllerDefinition.new(item)
    else
      item
    end
  end
end

Instance Method Details

#add_configuration(configuration) ⇒ Object


26
27
28
29
30
31
# File 'lib/releaf/configuration.rb', line 26

def add_configuration(configuration)
  configuration_name = configuration.class.name.gsub(/Configuration$/, "").split("::").last.underscore

  self.class.send(:attr_accessor, configuration_name)
  send("#{configuration_name}=", configuration)
end

#additional_controllers=(value) ⇒ Object


67
68
69
# File 'lib/releaf/configuration.rb', line 67

def additional_controllers=(value)
  super(self.class.normalize_controllers(value))
end

#all_localesObject


44
45
46
# File 'lib/releaf/configuration.rb', line 44

def all_locales
  @all_locales ||= (available_locales + available_admin_locales).map(&:to_s).uniq
end

#available_controllersObject


55
56
57
# File 'lib/releaf/configuration.rb', line 55

def available_controllers
  @available_controllers ||= controllers.keys
end

#components=(value) ⇒ Object


13
14
15
16
17
18
# File 'lib/releaf/configuration.rb', line 13

def components=(value)
  super(flatten_components(value))
  components.each do|component_class|
    component_class.configure_component if component_class.respond_to? :configure_component
  end
end

#controllersObject


59
60
61
# File 'lib/releaf/configuration.rb', line 59

def controllers
  @controllers ||= extract_controllers(menu + additional_controllers)
end

#extract_controllers(list) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/releaf/configuration.rb', line 71

def extract_controllers(list)
  list.each.inject({}) do |controller_list, item|
    if item.respond_to? :controllers
      controller_list.merge!(extract_controllers(item.controllers))
    else
      controller_list[item.controller_name] = item
    end

    controller_list
  end
end

#flatten_components(raw_components) ⇒ Object


48
49
50
51
52
53
# File 'lib/releaf/configuration.rb', line 48

def flatten_components(raw_components)
  raw_components.each.inject([]) do |list, component_class|
    list += flatten_components(component_class.components) if component_class.respond_to? :components
    list << component_class # add component itself latter as there can be dependancy to be loadable first
  end
end

#initialize_componentsObject


20
21
22
23
24
# File 'lib/releaf/configuration.rb', line 20

def initialize_components
  components.each do|component_class|
    component_class.initialize_component if component_class.respond_to? :initialize_component
  end
end

#initialize_defaultsObject


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

def initialize_defaults
  self.class.default_values.each_pair do|key, value|
    send("#{key}=", value)
  end
end

#initialize_localesObject


39
40
41
42
# File 'lib/releaf/configuration.rb', line 39

def initialize_locales
  ::I18n.available_locales = available_locales
  self.available_admin_locales = available_locales if available_admin_locales.empty?
end

63
64
65
# File 'lib/releaf/configuration.rb', line 63

def menu=(value)
  super(self.class.normalize_controllers(value))
end