Module: Inform::Modular
- Included in:
- Object
- Defined in:
- lib/runtime/module.rb
Overview
The Inform::Modular module
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #apply_modules(exceptions = []) ⇒ Object
- #mod(*args) ⇒ Object
- #modules ⇒ Object
- #modules_semaphore ⇒ Object
- #nil_safe_modules ⇒ Object
-
#reset_modules ⇒ Object
TODO: This is broken somehow FIXME.
- #unmod(*args) ⇒ Object
Instance Method Details
#after_initialize ⇒ Object
136 137 138 139 |
# File 'lib/runtime/module.rb', line 136 def after_initialize self.apply_modules super end |
#apply_modules(exceptions = []) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/runtime/module.rb', line 176 def apply_modules(exceptions = []) nil_safe_modules.each do |module_name| next if exceptions.include?(module_name.to_sym) mod = find_module(module_name) next if mod.nil? mod.ancestors.reverse.each do |ancestor| self.extend(ancestor) end end self end |
#mod(*args) ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/runtime/module.rb', line 147 def mod(*args) a = args.flatten.collect(&:to_s) (a - (nil_safe_modules & a)).each do |mod| add_module(Inform::Module.find_or_create(name: mod)) end save apply_modules self end |
#modules ⇒ Object
141 142 143 144 145 |
# File 'lib/runtime/module.rb', line 141 def modules super rescue StandardError => _e Array::Empty end |
#modules_semaphore ⇒ Object
168 169 170 |
# File 'lib/runtime/module.rb', line 168 def modules_semaphore @modules_semaphore ||= Mutex.new end |
#nil_safe_modules ⇒ Object
172 173 174 |
# File 'lib/runtime/module.rb', line 172 def nil_safe_modules modules.compact.map(&:to_s) end |
#reset_modules ⇒ Object
TODO: This is broken somehow FIXME
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/runtime/module.rb', line 189 def reset_modules nil_safe_modules.each do |module_name| remove_module(module_name) mod = find_module(module_name) next if mod.nil? mod.instance_methods.each { |method_name| undef_method(method_name) } end save self end |