Class: JSWebBuilder::TargetFile
- Inherits:
-
Object
- Object
- JSWebBuilder::TargetFile
- Defined in:
- lib/js_web_builder.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
The full path of the base file.
-
#include_list ⇒ Object
readonly
The include list after reading the base file.
Instance Method Summary collapse
-
#create_include_list ⇒ Object
:nodoc:.
-
#execute ⇒ Object
executes the concatenation and returns the result for further fun.
-
#initialize(params = {}) ⇒ TargetFile
constructor
create file reader.
Constructor Details
#initialize(params = {}) ⇒ TargetFile
create file reader
82 83 84 |
# File 'lib/js_web_builder.rb', line 82 def initialize params = {} params.each { |key, value| send "#{key}=", value } end |
Instance Attribute Details
#file ⇒ Object
The full path of the base file
76 77 78 |
# File 'lib/js_web_builder.rb', line 76 def file @file end |
#include_list ⇒ Object (readonly)
The include list after reading the base file
79 80 81 |
# File 'lib/js_web_builder.rb', line 79 def include_list @include_list end |
Instance Method Details
#create_include_list ⇒ Object
:nodoc:
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/js_web_builder.rb', line 99 def create_include_list # :nodoc: unless File.readable?(@file) raise "Can't open File: #{@file}" end @include_list = [] _i = 0 File.readlines(@file).each do |line| if _scan = line.match(/^\s*\/\/=\s+require\s+(.+)$/) @include_list << _scan[1] _full = File.join(File.dirname(@file),_scan[1]) unless File.readable?(_full) raise "Can't read #{_full} required from #{@file} in line #{_i}" end _i+=1 end end end |
#execute ⇒ Object
executes the concatenation and returns the result for further fun
93 94 95 96 97 |
# File 'lib/js_web_builder.rb', line 93 def execute res = @include_list.map { |re_file| IO.read File.join(File.dirname(@file),re_file) } res << IO.read(@file) res.join "\n" end |