module Ditty::Components
Ripped off from Roda - github.com/jeremyevans/roda
Public Class Methods
component?(name)
click to toggle source
# File lib/ditty.rb, line 72 def self.component?(name) @components.key? name end
components()
click to toggle source
# File lib/ditty.rb, line 85 def self.components @components end
load_component(name)
click to toggle source
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.
# File lib/ditty.rb, line 61 def self.load_component(name) h = @components unless (component = h[name]) require "ditty/components/#{name}" unless (component = h[name]) raise ComponentError, "Component #{name} did not register itself correctly in Ditty::Components" end end component end
migrations()
click to toggle source
# File lib/ditty.rb, line 106 def self.migrations components.map do |_name, comp| comp.migrations if comp.respond_to?(:migrations) end.compact end
public_folder()
click to toggle source
# File lib/ditty.rb, line 112 def self.public_folder components.map do |_name, comp| comp.public_folder if comp.respond_to?(:public_folder) end.compact end
register_component(name, mod)
click to toggle source
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)
# File lib/ditty.rb, line 80 def self.register_component(name, mod) ::Ditty::Services::Logger.info "Registering #{mod} as #{name}" @components[name] = mod end
routes()
click to toggle source
Return a hash of controllers with their routes as keys: `{ '/users' => Ditty::Controllers::Users }`
# File lib/ditty.rb, line 90 def self.routes rts = components.each_with_object({}) do |comp, memo| memo.merge! comp[1].routes if comp[1].respond_to?(:routes) end rts.compact end
seeders()
click to toggle source
# File lib/ditty.rb, line 118 def self.seeders components.map do |_name, comp| comp.seeder if comp.respond_to?(:seeder) end.compact end
tasks()
click to toggle source
# File lib/ditty.rb, line 130 def self.tasks require 'rake' require 'rake/tasklib' require 'ditty/db' unless defined? DB components.each do |_name, comp| comp.tasks if comp.respond_to?(:tasks) end end
workers()
click to toggle source
# File lib/ditty.rb, line 124 def self.workers components.each_with_object([]) do |comp, memo| memo.concat comp[1].workers if comp[1].respond_to?(:workers) end end