Module: OpenNamespace::ClassMethods
- Defined in:
- lib/open_namespace/class_methods.rb
Instance Method Summary collapse
-
#const_defined?(name, *inherit) ⇒ Boolean
Checks if a constant is defined or attempts loading the constant.
-
#const_lookup(name) ⇒ Object?
Finds the exact constant.
-
#const_missing(name) ⇒ Class, Module
protected
Provides transparent access to require_const.
-
#const_search(file_name) ⇒ Object?
Finds the constant with a name similar to the given file name.
-
#namespace_root ⇒ String
The file path that represents the namespace.
-
#namespace_root=(new_path) ⇒ String
Sets the file path of the namespace.
-
#require_const(name) ⇒ Class, ...
Requires the file and finds the newly defined constant.
-
#require_file(name) ⇒ true?
Requires the file with the given name, within the namespace root directory.
Instance Method Details
#const_defined?(name, *inherit) ⇒ Boolean
Checks if a constant is defined or attempts loading the constant.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/open_namespace/class_methods.rb', line 96 def const_defined?(name,*inherit) if super(name,*inherit) true else # attempt to load the file that might have the constant require_file(OpenNamespace.const_path(name)) # check for the constant again return super(name,*inherit) end end |
#const_lookup(name) ⇒ Object?
Finds the exact constant.
119 120 121 |
# File 'lib/open_namespace/class_methods.rb', line 119 def const_lookup(name) OpenNamespace.const_lookup(self,name) end |
#const_missing(name) ⇒ Class, Module (protected)
Provides transparent access to require_const.
155 156 157 158 159 160 161 162 |
# File 'lib/open_namespace/class_methods.rb', line 155 def const_missing(name) if self.const_defined?(name) # get the exact constant name that was requested return self.const_get(name) end return super(name) end |
#const_search(file_name) ⇒ Object?
Finds the constant with a name similar to the given file name.
135 136 137 |
# File 'lib/open_namespace/class_methods.rb', line 135 def const_search(file_name) OpenNamespace.const_search(self,file_name) end |
#namespace_root ⇒ String
The file path that represents the namespace.
11 12 13 |
# File 'lib/open_namespace/class_methods.rb', line 11 def namespace_root @namespace_root ||= OpenNamespace.const_path(self.name) end |
#namespace_root=(new_path) ⇒ String
Sets the file path of the namespace.
24 25 26 |
# File 'lib/open_namespace/class_methods.rb', line 24 def namespace_root=(new_path) @namespace_root = new_path.to_s end |
#require_const(name) ⇒ Class, ...
Requires the file and finds the newly defined constant.
47 48 49 50 51 |
# File 'lib/open_namespace/class_methods.rb', line 47 def require_const(name) require_file(name) return const_search(name) end |
#require_file(name) ⇒ true?
Requires the file with the given name, within the namespace root directory.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/open_namespace/class_methods.rb', line 69 def require_file(name) name = name.to_s path = File.join(namespace_root,File.(File.join('',name))) begin require path rescue Gem::LoadError => e raise(e) rescue ::LoadError return nil end return true end |