Class: EacRubyUtils::Templates::File
- Defined in:
- lib/eac_ruby_utils/templates/file.rb
Constant Summary collapse
- VARIABLE_DELIMITER =
::Regexp.quote('%%')
- VARIABLE_PATTERN =
/#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
Instance Method Summary collapse
-
#apply(variables_source) ⇒ Object
variables_provider
A [Hash] or object which responds to read_entry(entry_name). - #apply_to_file(variables_source, output_file_path) ⇒ Object
Instance Method Details
#apply(variables_source) ⇒ Object
variables_provider
A [Hash] or object which responds to read_entry(entry_name).
18 19 20 21 22 23 |
# File 'lib/eac_ruby_utils/templates/file.rb', line 18 def apply(variables_source) variables_provider = ::EacRubyUtils::Templates::VariableProviders.build(variables_source) variables.inject(content) do |a, e| a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s) end end |
#apply_to_file(variables_source, output_file_path) ⇒ Object
25 26 27 |
# File 'lib/eac_ruby_utils/templates/file.rb', line 25 def apply_to_file(variables_source, output_file_path) output_file_path.to_pathname.write(apply(variables_source)) end |