Class: SourceFile
- Inherits:
-
Object
- Object
- SourceFile
- Defined in:
- lib/javascript_auto_include/source_file.rb
Instance Method Summary collapse
-
#dependencies(force = false) ⇒ Object
Read dependencies from config file or scan source file.
-
#initialize(files) ⇒ SourceFile
constructor
Retrieve javascript file as full path.
Constructor Details
#initialize(files) ⇒ SourceFile
Retrieve javascript file as full path
6 7 8 9 10 11 |
# File 'lib/javascript_auto_include/source_file.rb', line 6 def initialize(files) Dir.mkdir("#{::Rails.root}#{File::SEPARATOR}config#{File::SEPARATOR}dependencies") unless Dir.exists?("#{::Rails.root}#{File::SEPARATOR}config#{File::SEPARATOR}dependencies") @config_files = files.collect { |file| [file, "#{::Rails.root}#{File::SEPARATOR}config#{File::SEPARATOR}dependencies#{File::SEPARATOR}#{file}.yml"] } @source_files = files.collect { |file| [file, "#{::Rails.root}#{File::SEPARATOR}public#{File::SEPARATOR}javascripts#{File::SEPARATOR}#{file}#{file.match(/\.js$/) ? '' : '.js' }"] } @dependencies = Dependency.new end |
Instance Method Details
#dependencies(force = false) ⇒ Object
Read dependencies from config file or scan source file
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/javascript_auto_include/source_file.rb', line 14 def dependencies(force = false) 0.upto(@source_files.size-1) do |i| if force || !config_exists?(i) @dependencies += read_from_source(@source_files[i], @config_files[i]) if File.exists?(@source_files[i][1]) else @dependencies += read_from_config(@config_files[i]) end end ENV["RAILS_ENV"] == 'production' ? minify(@dependencies.uniq) : @dependencies.uniq end |