Class: Quir::Loader
- Inherits:
-
Object
- Object
- Quir::Loader
- Defined in:
- lib/quir/loader.rb
Instance Attribute Summary collapse
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#module ⇒ Object
readonly
Returns the value of attribute module.
Instance Method Summary collapse
- #append_directory(d) ⇒ Object
- #append_ruby_file(f) ⇒ Object
-
#initialize(mod, dir) ⇒ Loader
constructor
A new instance of Loader.
- #run ⇒ Object
Constructor Details
#initialize(mod, dir) ⇒ Loader
Returns a new instance of Loader.
7 8 9 10 |
# File 'lib/quir/loader.rb', line 7 def initialize(mod, dir) @module = mod @dir = dir end |
Instance Attribute Details
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
5 6 7 |
# File 'lib/quir/loader.rb', line 5 def binding @binding end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
12 13 14 |
# File 'lib/quir/loader.rb', line 12 def dir @dir end |
#module ⇒ Object (readonly)
Returns the value of attribute module.
12 13 14 |
# File 'lib/quir/loader.rb', line 12 def module @module end |
Instance Method Details
#append_directory(d) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/quir/loader.rb', line 24 def append_directory(d) return if ::File.exist?("#{dir}/#{d}.rb") name = d.split(/\//)[-1].pascalize return if self.module.const_defined?(name, false) m = ::Module.new self.module.const_set name, m m.name # fix module's name loader = ::Quir::Loader.new(m, d) loader.run end |
#append_ruby_file(f) ⇒ Object
35 36 37 38 |
# File 'lib/quir/loader.rb', line 35 def append_ruby_file(f) name = f.split(/\//)[-1].sub(/\.rb$/, '').pascalize self.module.autoload name, f unless self.module.autoload?(name) end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/quir/loader.rb', line 14 def run ::Dir.glob("#{dir}/*") do |f| if ::File.directory?(f) append_directory f elsif /\.rb$/ =~ f append_ruby_file f end end end |