Class: Vars
- Inherits:
-
Object
- Object
- Vars
- Extended by:
- Forwardable
- Defined in:
- lib/vars.rb,
lib/vars/options.rb,
lib/vars/version.rb
Defined Under Namespace
Classes: Options
Constant Summary collapse
- VERSION =
"0.0.4".freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(opts = {}) ⇒ Vars
constructor
A new instance of Vars.
- #resolve_template(template_file, output_file) ⇒ Object
- #resolve_templates(template_path, output_path, excludes: []) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
49 50 51 52 |
# File 'lib/vars.rb', line 49 def method_missing(name, *args, &block) super unless hash.key?(name.to_s) hash.fetch(name.to_s) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/vars.rb', line 13 def @options end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/vars.rb', line 20 def [](key) hash[key.to_s] end |
#resolve_template(template_file, output_file) ⇒ Object
41 42 43 44 45 |
# File 'lib/vars.rb', line 41 def resolve_template(template_file, output_file) ::File.open(output_file, "w") do |f| f.write(::ERB.new(::File.read(template_file), nil, "-").result(__binding__)) end end |
#resolve_templates(template_path, output_path, excludes: []) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vars.rb', line 24 def resolve_templates(template_path, output_path, excludes: []) template_path = ::Pathname.new(template_path) output_path = ::Pathname.new(output_path) excludes = excludes.map(&:to_s) template_path.glob("**/*").each do |template_file| next if template_file.directory? filename = template_file.basename(".erb") next unless ([filename.to_s, template_file.basename.to_s] & excludes).empty? resolve_template( template_file, output_path.join(template_file.dirname.join(filename).relative_path_from(template_path)) ) end end |