Module: Refrigerator
- Defined in:
- lib/refrigerator.rb
Overview
Refrigerator allows for easily freezing core classes and modules.
Constant Summary collapse
- CORE_MODULES =
Array of strings containing class or module names.
File.read(File.(File.join(File.(__FILE__), "../../module_names/#{version_int}.txt"))). split(/\s+/). select{|m| eval("defined?(#{m})")}. each(&:freeze). freeze
- OPTS =
Default frozen options hash
{}.freeze
Class Method Summary collapse
-
.check_require(file, opts = OPTS) ⇒ Object
Check that requiring a given file does not modify any core classes.
-
.freeze_core(opts = OPTS) ⇒ Object
Freeze core classes and modules.
Class Method Details
.check_require(file, opts = OPTS) ⇒ Object
Check that requiring a given file does not modify any core classes. Options:
- :depends
-
Require the given files before freezing the core (array of strings)
- :modules
-
Define the given modules in the Object namespace before freezing the core (array of module name symbols)
- :classes
-
Define the given classes in the Object namespace before freezing the core (array of either class name Symbols or array with class Name Symbol and Superclass name string)
- :except
-
Don’t freeze any of the classes modules listed (array of strings)
29 30 31 32 33 34 35 36 |
# File 'lib/refrigerator.rb', line 29 def self.check_require(file, opts=OPTS) require 'rubygems' Array(opts[:depends]).each{|f| require f} Array(opts[:modules]).each{|m| Object.const_set(m, Module.new)} Array(opts[:classes]).each{|c, *sc| Object.const_set(c, Class.new(sc.empty? ? Object : eval(sc.first.to_s)))} freeze_core(:except=>%w'Gem Gem::Specification'+Array(opts[:exclude])) require file end |
.freeze_core(opts = OPTS) ⇒ Object
Freeze core classes and modules. Options:
- :except
-
Don’t freeze any of the classes modules listed (array of strings)
18 19 20 21 |
# File 'lib/refrigerator.rb', line 18 def self.freeze_core(opts=OPTS) (CORE_MODULES - Array(opts[:except])).each{|m| eval(m).freeze} nil end |