Module: Ditty::Components
- Defined in:
- lib/ditty.rb
Overview
Ripped off from Roda - github.com/jeremyevans/roda
Defined Under Namespace
Modules: Base
Class Method Summary collapse
- .components ⇒ Object
-
.load_component(name) ⇒ Object
If the registered component already exists, use it.
- .migrations ⇒ Object
- .migrations=(migrations) ⇒ Object
- .navigation ⇒ Object
- .navigation=(navigation) ⇒ Object
-
.register_component(name, mod) ⇒ Object
Register the given component with Component, so that it can be loaded using #component with a symbol.
-
.routes ⇒ Object
Return a hash of controllers with their routes as keys: ‘{ ’/users’ => Ditty::Controllers::Users }‘.
- .routes=(routes) ⇒ Object
- .seeders ⇒ Object
- .seeders=(seeders) ⇒ Object
- .workers ⇒ Object
- .workers=(workers) ⇒ Object
Class Method Details
.components ⇒ Object
64 65 66 |
# File 'lib/ditty.rb', line 64 def self.components @components end |
.load_component(name) ⇒ Object
If the registered component already exists, use it. Otherwise, require it and return it. This raises a LoadError if such a component doesn’t exist, or a Component if it exists but it does not register itself correctly.
46 47 48 49 50 51 52 53 |
# File 'lib/ditty.rb', line 46 def self.load_component(name) h = @components unless (component = h[name]) require "ditty/components/#{name}" raise ComponentError, "Component #{name} did not register itself correctly in Ditty::Components" unless (component = h[name]) end component end |
.migrations ⇒ Object
87 88 89 |
# File 'lib/ditty.rb', line 87 def self.migrations @migrations ||= [] end |
.migrations=(migrations) ⇒ Object
91 92 93 |
# File 'lib/ditty.rb', line 91 def self.migrations=(migrations) @migrations = migrations end |
.navigation ⇒ Object
79 80 81 |
# File 'lib/ditty.rb', line 79 def self. ||= [] end |
.navigation=(navigation) ⇒ Object
83 84 85 |
# File 'lib/ditty.rb', line 83 def self.=() = end |
.register_component(name, mod) ⇒ Object
Register the given component with Component, so that it can be loaded using #component with a symbol. Should be used by component files. Example:
Ditty::Components.register_component(:component_name, ComponentModule)
59 60 61 62 |
# File 'lib/ditty.rb', line 59 def self.register_component(name, mod) puts "Registering #{mod} as #{name}" @components[name] = mod end |
.routes ⇒ Object
Return a hash of controllers with their routes as keys: ‘{ ’/users’ => Ditty::Controllers::Users }‘
69 70 71 |
# File 'lib/ditty.rb', line 69 def self.routes @routes ||= {} end |
.routes=(routes) ⇒ Object
73 74 75 |
# File 'lib/ditty.rb', line 73 def self.routes=(routes) @routes = routes end |
.seeders ⇒ Object
95 96 97 |
# File 'lib/ditty.rb', line 95 def self.seeders @seeders ||= [] end |
.seeders=(seeders) ⇒ Object
99 100 101 |
# File 'lib/ditty.rb', line 99 def self.seeders=(seeders) @seeders = seeders end |
.workers ⇒ Object
103 104 105 |
# File 'lib/ditty.rb', line 103 def self.workers @workers ||= [] end |
.workers=(workers) ⇒ Object
107 108 109 |
# File 'lib/ditty.rb', line 107 def self.workers=(workers) @workers = workers end |