Module: Watchdog
- Defined in:
- lib/watchdog.rb,
lib/watchdog/error.rb,
lib/watchdog/version.rb,
lib/watchdog/german_shepard.rb
Defined Under Namespace
Modules: GermanShepard Classes: Error, ExtensionMethodExistsError, MethodExistsError
Constant Summary collapse
- VERSION =
'0.3.0'
Class Attribute Summary collapse
-
.extensions ⇒ Object
Returns the value of attribute extensions.
-
.sleep ⇒ Object
Returns the value of attribute sleep.
-
.subclasses ⇒ Object
Returns the value of attribute subclasses.
Class Method Summary collapse
-
.guard(obj, meth) ⇒ Object
Guards extension methods from being overwritten.
- .setup_guard(extension, extended) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.extensions ⇒ Object
Returns the value of attribute extensions.
6 7 8 |
# File 'lib/watchdog.rb', line 6 def extensions @extensions end |
.sleep ⇒ Object
Returns the value of attribute sleep.
6 7 8 |
# File 'lib/watchdog.rb', line 6 def sleep @sleep end |
.subclasses ⇒ Object
Returns the value of attribute subclasses.
6 7 8 |
# File 'lib/watchdog.rb', line 6 def subclasses @subclasses end |
Class Method Details
.guard(obj, meth) ⇒ Object
Guards extension methods from being overwritten
12 13 14 15 16 17 18 19 |
# File 'lib/watchdog.rb', line 12 def self.guard(obj, meth) return if subclasses.include?(obj) || (sleep && sleep.call) return subclasses << obj if !extensions.key?(obj) && extensions.keys. any? {|e| e.is_a?(Module) && e > obj } if extensions[obj].instance_methods.map(&:to_sym).include?(meth) raise ExtensionMethodExistsError.new(meth, obj, extensions[obj]) end end |
.setup_guard(extension, extended) ⇒ Object
21 22 23 24 |
# File 'lib/watchdog.rb', line 21 def self.setup_guard(extension, extended) extensions[extended] = extension extended.extend GermanShepard end |
Instance Method Details
#append_features(mod) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/watchdog.rb', line 26 def append_features(mod) Watchdog.setup_guard(self, mod) existing = mod.private_instance_methods + mod.instance_methods (existing & self.instance_methods).each do |m| raise MethodExistsError.new(m, self, mod) end super end |
#extend_object(obj) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/watchdog.rb', line 35 def extend_object(obj) Watchdog.setup_guard(self, obj) self.instance_methods.each do |m| raise MethodExistsError.new(m, self, obj) if obj.respond_to?(m, true) end super end |