Sha256: 453fc0b2c2a27ed5b5431233e203d620f3b6e330863541911dc340329853fb33

Contents?: true

Size: 828 Bytes

Versions: 5

Compression:

Stored size: 828 Bytes

Contents

class Module
  
  # Bulk converts the security level of methods in this Module from one level to another.
  def convert_security_of_methods(old_level = :public, new_level = :protected)
    eval("#{old_level}_instance_methods").each{ |meth| self.send(:protected, meth) }
    self
  end
  
  # Includes this module into an Object, and changes all public methods to protected.
  # 
  # Examples:
  #   module MyCoolUtils
  #     def some_meth
  #       "hi"
  #     end
  #     self.include_safely_into(FooController)
  #   end
  # or:
  #   MyCoolUtils.include_safely_into(FooController, SomeOtherClass)
  def include_safely_into(*args)
    [args].flatten.each do |a|
      if a.is_a?(String) || a.is_a?(Symbol)
        a = a.to_s.constantize
      end
      a.send(:include, self.convert_security_of_methods)
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mack-0.0.3 core_extensions/module.rb
mack-0.0.4 core_extensions/module.rb
mack-0.0.5 core_extensions/module.rb
mack-0.0.6.1 core_extensions/module.rb
mack-0.0.6 core_extensions/module.rb