Class: Vbuilder::Generator
- Inherits:
-
Object
- Object
- Vbuilder::Generator
- Defined in:
- lib/vbuilder/generator.rb,
lib/vbuilder/generator/options.rb,
lib/vbuilder/generator/provider.rb,
lib/vbuilder/generator/application.rb
Defined Under Namespace
Classes: Application, Options, Provider
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
-
#get_provider_attrs ⇒ Object
Helper functions TODO: Move these functions to lib/helpers.rb.
- #get_template_file ⇒ Object
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
14 15 16 17 |
# File 'lib/vbuilder/generator.rb', line 14 def initialize( = {}) @options = @provider = [:provider] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/vbuilder/generator.rb', line 12 def @options end |
#provider ⇒ Object
Returns the value of attribute provider.
12 13 14 |
# File 'lib/vbuilder/generator.rb', line 12 def provider @provider end |
Instance Method Details
#get_provider_attrs ⇒ Object
Helper functions TODO: Move these functions to lib/helpers.rb
34 35 36 37 38 39 |
# File 'lib/vbuilder/generator.rb', line 34 def get_provider_attrs attrs_file = "../generator/attributes/#{@provider}.yaml" attrs_file = File.(attrs_file, __FILE__) YAML.load(File.read(attrs_file)) end |
#get_template_file ⇒ Object
41 42 43 44 45 46 |
# File 'lib/vbuilder/generator.rb', line 41 def get_template_file template_file = "../templates/master.erb" template_file = File.(template_file, __FILE__) File.read(template_file) end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vbuilder/generator.rb', line 19 def run provider_attrs = get_provider_attrs provider = Vbuilder::Generator::Provider.new(provider_attrs) template_file = get_template_file renderer = ERB.new(template_file).result(provider.get_binding) File.open('Vagrantfile', 'w+') do |f| f.write(renderer) end end |