Class: Require
Class Attribute Summary collapse
-
.path_to_gems ⇒ Object
Returns the value of attribute path_to_gems.
Class Method Summary collapse
- .add_load_path(path) ⇒ Object
- .files_for(path) ⇒ Object
- .files_in(path) ⇒ Object
- .gem_path(gem) ⇒ Object
- .require_unpacked_gem(gem) ⇒ Object
- .unpacked_gem(*gem_names) ⇒ Object
Class Attribute Details
.path_to_gems ⇒ Object
Returns the value of attribute path_to_gems.
3 4 5 |
# File 'lib/thoughtful/require.rb', line 3 def path_to_gems @path_to_gems end |
Class Method Details
.add_load_path(path) ⇒ Object
35 36 37 |
# File 'lib/thoughtful/require.rb', line 35 def self.add_load_path(path) $: << path end |
.files_for(path) ⇒ Object
26 27 28 |
# File 'lib/thoughtful/require.rb', line 26 def self.files_for(path) Dir["#{RAILS_ROOT}/#{path}/*"] end |
.files_in(path) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/thoughtful/require.rb', line 6 def self.files_in(path) files = files_for(path) raise ArgumentError.new("no files found in #{path}") if files.empty? files.each do |file| require file end end |
.gem_path(gem) ⇒ Object
30 31 32 33 |
# File 'lib/thoughtful/require.rb', line 30 def self.gem_path(gem) return Dir[path_to_gems + "#{gem}*"] if path_to_gems Dir[RAILS_ROOT + "/vendor/gems/#{gem}*"] end |
.require_unpacked_gem(gem) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/thoughtful/require.rb', line 18 def self.require_unpacked_gem(gem) raise ArgumentError.new("unpacked gem #{gem} could not be found") if gem_path(gem).empty? gem_path(gem).each do |dir| add_load_path "#{dir}/lib" require dir + "/lib/#{gem}" if File.exist?(dir + "/lib/#{gem}.rb") end end |
.unpacked_gem(*gem_names) ⇒ Object
14 15 16 |
# File 'lib/thoughtful/require.rb', line 14 def self.unpacked_gem(*gem_names) gem_names.each { |gem| require_unpacked_gem(gem) } end |