Class: Cassie::Configuration::Generator
- Includes:
- ERB::Util
- Defined in:
- lib/cassie/configuration/generator.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Generator
constructor
A new instance of Generator.
- #render ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Generator
Returns a new instance of Generator.
11 12 13 14 15 |
# File 'lib/cassie/configuration/generator.rb', line 11 def initialize(opts={}) @app_name = opts.fetch(:app_name, default_app_name) @template_path = opts.fetch(:template_path, default_template_path) @destination_path = opts.fetch(:destination_path, default_destination_path) end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
7 8 9 |
# File 'lib/cassie/configuration/generator.rb', line 7 def app_name @app_name end |
#destination_path ⇒ Object
Returns the value of attribute destination_path.
7 8 9 |
# File 'lib/cassie/configuration/generator.rb', line 7 def destination_path @destination_path end |
#template_path ⇒ Object
Returns the value of attribute template_path.
7 8 9 |
# File 'lib/cassie/configuration/generator.rb', line 7 def template_path @template_path end |
Instance Method Details
#render ⇒ Object
17 18 19 |
# File 'lib/cassie/configuration/generator.rb', line 17 def render ERB.new(template).result(binding) end |
#save ⇒ Object
21 22 23 24 25 26 |
# File 'lib/cassie/configuration/generator.rb', line 21 def save raise "#{destination_path} already exists" if File.exists?(destination_path) File.open(destination_path, "w+") do |f| f.write(render) end end |