Module: YouthTree::ControllerExt
- Defined in:
- lib/youth_tree/controller_ext.rb
Defined Under Namespace
Modules: ClassMethods Classes: Railtie
Constant Summary collapse
- VERSION =
"0.1.2".freeze
Class Method Summary collapse
-
.[](name) ⇒ Object
Lookup controller extensions.
- .for(name, &blk) ⇒ Object
- .load_default! ⇒ Object
Class Method Details
.[](name) ⇒ Object
Lookup controller extensions.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/youth_tree/controller_ext.rb', line 20 def self.[](name) name = name.to_sym if known_extensions.has_key?(name) return known_extensions[name] else constant_name = "#{name.to_s.classify}Ext" [nil, "YouthTree::ControllerExt", "YouthTree", "ControllerExt"].each do |namespace| full = [namespace, constant_name].compact.join("::") begin constant = full.constantize known_extensions[name] = constant return constant rescue NameError end end nil end end |
.for(name, &blk) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/youth_tree/controller_ext.rb', line 39 def self.for(name, &blk) constant_name = "#{name.to_s.classify}Ext" const_set(constant_name, Module.new) unless const_defined?(constant_name) const_get(constant_name).tap do |m| m.module_eval(&blk) if blk.present? end end |
.load_default! ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/youth_tree/controller_ext.rb', line 11 def self.load_default! dir = File.("controller_ext", File.dirname(__FILE__)) Dir[File.join(dir, "*.rb")].each do |f| require f end known_extensions[:pseudocephalopod_resource] = YouthTree::ControllerExt::SluggedResourceExt end |